[SDL] OpenGL problem...

Dirk Gerrits dirkg at chello.nl
Sat Mar 2 10:01:01 PST 2002


> > Hi,
> >
> > I've got a problem with OpenGL. I found an example of drawing a skybox
for
> > windows
> > and converted it to SDL, but when I ran it created a white border around
> > the texture.
> > I tested another texture, in which I had drawed a green line at the
bottom
> > of the image,
> > and found some green at the top of the texture! I use the same code, the
> > only differens is
> > that I use 24bit bmp's and the example uses 8bit bmp's.
> > I use LoadBMP from the NEHE SDL OPENGL example...
> >
> > I think it's an OpenGL problem but since I use the same OpenGL code...
> > OpenGL or SDL problem?
>
> Sounds like an OpenGL thing. Note that textures are wrapped by default,
and
> with linear filtering, wrapping will influence the edges of a polygon even
if
> the texture fits "exactly".
>
> You've got two choices basically: Either disable wrapping
> (glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP), same for
WRAP_T).

Actually you should use GL_CLAMP_TO_EDGE (OpenGL 1.2 or higher,
GL_EXT_texture_edge_clamp or GL_SGIS_texture_edge_clamp). On when that is
not
supported should you fall back to GL_CLAMP. That is because GL_CLAMP is
supposed
to use border pixels in the filtering process and GL_CLAMP_TO_EDGE does not.
However, on earlier nVidia cards, GL_CLAMP worked as GL_CLAMP_TO_EDGE works.
(I've been told it's a hardware bug.)

> Or, you could use texture coordinates so that they're actually in the
middle
> of the border texels, i.e.:
>
> int tw, th; // texture size
>
> s1 = 0.5 / tw;
> s2 = (tw - 0.5) / tw;
> t1= 0.5 / th;
> t2 = (th - 0.5) / th;

Yes I suppose this would do the same trick.

Dirk Gerrits






More information about the SDL mailing list