Lines antialiasing produces incorrect results

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:

Zoomed part:

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);

Well, these lines helped me :slight_smile:


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

Although I don’t actually know how they work :slight_smile:

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.