next up previous contents
Next: 7.2.1 glPolygonOffset Up: 7. Line Rendering Techniques Previous: 7.1 Wireframe Models

   
7.2 Hidden Lines

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 [52] [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:

1.
Disable writing to the color buffer with glColorMask().
2.
Enable depth testing with glEnableGL_DEPTH_TEST(GL_DEPTH_TEST).
3.
Render the object as polygons.
4.
Enable writing to the color buffer.
5.
Render the object as edges using one of the methods described in Section 7.1.

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:

1.
Disable writing to the color buffer with glColorMask().
2.
Disable depth testing; glDisableGL_DEPTH_TEST(GL_DEPTH_TEST).
3.
Enable stenciling; glEnableGL_STENCIL_TEST(GL_STENCIL_TEST).
4.
Clear the stencil buffer.
5.
Set the stencil buffer to set the stencil values to 1 where pixels are drawn; glStencilFuncGL_ALWAYS, 1, 1(GL_ALWAYS, 1, 1); glStencilOpGL_REPLACE, GL_REPLACE, GL_REPLACE(GL_REPLACE, GL_REPLACE, GL_REPLACE).
6.
Render the object as edges.
7.
Use the stencil buffer to mask out pixels where the stencil value is 1; glStencilFuncGL_EQUAL, 1, 1(GL_EQUAL, 1, 1) and glStencilOpGL_KEEP, GL_KEEP, GL_KEEP(GL_KEEP, GL_KEEP, GL_KEEP).
8.
Render the object as polygons.
9.
Turn off stenciling glDisableGL_STENCIL_TEST(GL_STENCIL_TEST).
10.
Enable writing to the color buffer.
11.
Render the object as edges using one of the methods described in Section 7.1.

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:

1.
Leave the color depth buffer enabled for writing.
2.
Set the color and/or pattern you want for the hidden lines.
3.
Render the object as edges.
4.
Disable writing to the color buffer.
5.
Render the object as polygons.
6.
Set the color and/or pattern you want for the visible lines.
7.
Render the object as edges using one of the methods described in Section 7.1.

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.



 
next up previous contents
Next: 7.2.1 glPolygonOffset Up: 7. Line Rendering Techniques Previous: 7.1 Wireframe Models
David Blythe
1999-08-06