PDA

View Full Version : Lines antialiasing produces incorrect results



Glex1
08-03-2008, 04:07 PM
Basically, the problem is that lines look bad when they are on a polygon surface.

This issue somehow happens even with GL_LEQUAL depth test.
But if you clear depth buffer between polygons- and lines-drawing calls, lines are antialiased perfectly.

I don't know, why that happens. Maybe that should've been posted in the begginers' thread. Does anyone know what to do?

The screenshots which demonstrate the problem:
http://img150.imageshack.us/img150/7273/antialiasingissuelf3.th.png (http://img150.imageshack.us/my.php?image=antialiasingissuelf3.png)

Zoomed part:
http://img150.imageshack.us/img150/9444/antialiasingissuezoominsf3.png (http://imageshack.us)

Initialization code


...
gl.glEnable(GL_BLEND);
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

gl.glEnable(GL_DEPTH_TEST);
gl.glDepthFunc(GL_LEQUAL);

gl.glEnable(GL_LINE_SMOOTH);
gl.glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

Glex1
08-03-2008, 04:25 PM
Well, these lines helped me :)


gl.glEnable(GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(1.0f, 1.0f);


Although I don't actually know how they work :)

James W. Walker
08-03-2008, 04:39 PM
I believe the reason is what's known as z-fighting. The fragments produced by the lines don't always have exactly the same depth as those produced by the polygons, so sometimes they lose the depth test. glPolygonOffset is a way of artificially tweaking the depth value so that the lines will win the depth test.