GL_LINE_SMOOTH bug?

I’m trying to render 1D textured lines to indicate relationships between objects. The textured lines always look fine when GL_LINE_SMOOTH is not enabled. However, if I turn GL_LINE_SMOOTH on, and change the modelview matrix such that at least one end of the line is off the viewport, the texturing goes haywire. The texture will stretch until a point at which it actually reverses direction.

It always seems to work perfectly fine when both of the line endpoints are within the viewport. This rendering oddity is even more obvious if the texture is animated to look like it’s flowing one direction, because the animation direction will flip as well when one endpoint is off the screen. This behavior appears regardless of whether I’m using mipmapping.

Here is some example C code (hopefully I’m not missing anything… distilled this out of a much larger project):

//make a line that is easy to tell which direction it is going
struct RGBAColor {unsigned char r, g, b, a; };
for(int i = 0; i < 256; i++)
dots[i].r = dots[i].g = dots[i].b = dots[i].a = (i & 63) * 255 / 64;

glEnable(GL_TEXTURE_1D);
glBindTexture(GL_TEXTURE_1D, 4);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D, 0, 4, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, &dots);

...
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINES);
glColor4ub(255,255,255,255);
glTexCoord1f(0.0);
glVertex3f(0.0, 0.0, 0.0);
glTexCoord1f(24.0);
glVertex3f(20.0, 10.0, 10.0);
glEnd(GL_LINES);
  

I’m using an ATI x800 Pro with the Catalyst 6.10 drivers. However, I remember finding this bug one other time about a year ago, and that may have been with my 9800 Pro with obviously older drivers. I don’t have easy access to other brand video cards to try this on.

I know 1D textures aren’t used much, but has anyone else seen this? I’d like to be able to use GL_LINE_SMOOTH, and drawing lines with 1D textures is easier than using cylinders or something.

It seems like a driver problem with texture perspective correction/clipping. On many implementations anti-aliased lines are drawn as textured quads, perhaps that somehow breaks texture_1d lines.

Your code looks fine.

Have you tried glHint with GL_LINE_SMOOTH_HINT and GL_PERSPECTIVE_CORRECTION_HINT?

You can try a one pixel wide texture_2d instead, though I’m not sure how widely supported anti aliased textured lines are (I know it falls back to software on GeForce4 Ti 4200).

Note: In case you are drawing dotted lines you might want to look for the function glLineStipple.

Hi remdul,

Thanks for the ideas. Unfortunately I do think you’re right in it being a driver problem.

I tried setting both of the hints to nicest, but that didn’t affect anything. I tried the line stipple idea (good idea, btw), but that gave other different odd behavior. It might be due to my view being perspective (vs ortho) and the stipple just changes because the number of pixels rendered for the line is changing when you move about in 3d. The dots seemed to change when I had both of the line’s vertexes on screen, but seemed to remain fairly consistent when one of them was on screen and the other was off. It’s a bit too disorienting to have the dotted lines moving like that though. Stippling doesn’t work as well either for the purpose though, which is to indicate relationships via dashed gradients moving in the direction of the relationship.

I also tried to see if I could get 2d textures to work with lines, but no such luck (though I’d always be worried about it working properly on other cards/drivers if it did work :wink: ).

To make it work it sounds like I need to either anti-alias the whole scene (which makes the fonts look blurry unless I change some stuff), or to project the coordinates and then billboard a thin quad and then use a regular 1 pixel wide 2d texture (not sure if I can easily do that types of billboarding on the GPU without vertex shaders or doing stuff on the CPU side… I’ll be thinking about it).

In that situation I would definately attempt to use textured quads. If you use linear filtering and alpha blend a 1xN texture map (use border color to make the edges transparant), you can still simulate anti aliased lines. Compute the coordinates on CPU. If you make sure the width of the quads remain 3px wide you should be able to emulate line smoothing very well. Can also try to use anisotropic filtering to improve the line quality.