This section describes techniques to draw wireframe objects with the hidden lines removed or drawn in a style different from the ones that are visible. This technique can clarify complex line drawings of objects, and improve their appearance [55] [5].
The algorithm assumes that the object is composed of polygons. The algorithm first renders the polygons of the objects, then the edges themselves, which make up the line drawing. During the first pass, only the depth buffer is updated. During the second pass, the depth buffer only allows edges that are not obscured by the object's polygons to be rendered, leaving the previous contents of the frame buffer undisturbed everywhere an edge is not drawn.
Here's the algorithm in detail:
For best results the lines should be offset from the polygons using either glPolygonOffset() or glDepthRange() to help reduce depth buffer aliasing artifacts.
The stencil buffer may be used to avoid the depth buffering artifacts for convex objects drawn using non-antialiased (jaggy) lines all of one color. The following technique uses the stencil buffer to mask where all the lines are (both hidden and visible). Then it uses the stencil function to prevent the polygon rendering from updating the depth buffer where the stencil values have been set. When the visible lines are rendered, there is no depth value conflict, since the polygons never touched those pixels.
Here's the modified algorithm:
Variants of the above algorithm may be applied to each convex part of an object or, if the topology of the object is not known, to each individual polygon to render well-behaved hidden line images.
Instead of removing hidden lines, sometimes it's desirable to render them with a different color or pattern. This can be done with a modification of the algorithm:
In this technique, all the edges are drawn twice; first with the hidden line pattern, then with the visible one. Rendering the object as polygons updates the depth buffer, preventing the second pass of line drawing from effecting the hidden lines.