next up previous contents
Next: 9.2 Polygon Antialiasing Up: 9 Antialiasing Previous: 9 Antialiasing   Contents

9.1 Line and Point Antialiasing

Line and point antialiasing should be considered separately from polygon antialiasing since the techniques are usually quite different. Mathematically, a line is infinitely thin. Attempting to compute the percentage of a pixel covered by an infinitely thin object would be impossible, so generally one of the following two methods is used:

  1. The line is modeled as a long, thin, single-pixel-wide quadrilateral. The percentage of pixel coverage is computed for each pixel touching the line and this coverage percentage is used as the alpha value for blending.

  2. The line is modeled as an infinitely thin transparent glowing object. This method treats a line as if drawn on a vector stroke display where the display draws a line by deflecting the electron beam as opposed to a raster display that moves the beam in horizontal scans and varies the beam intensity. This approach requires the implementation to compute the effective shape of an electron beam as it moves across the CRT phosphors.

To antialias points or lines in OpenGL, you need to enable antialiasing by calling glEnable() and passing in GL_ POINT_SMOOTH or GL_ LINE_SMOOTH, as appropriate. You can also provide a quality hint by calling glHint(). The hint parameter can be GL_ FASTEST to indicate that the most efficient option should be chosen, GL_ NICEST to indicate the highest quality option should be chosen, or GL_ DONT_CARE to indicate no preference.

When antialiasing is enabled, OpenGL computes an alpha value representing either the fraction of each pixel that is covered by the line or point or the beam intensity for the pixel as a function of the distance of the pixel center from the line center. The setting of the GL_ LINE_SMOOTH and the GL_ POINT_SMOOTH hints determine how accurate the calculation is when rendering lines and points, respectively. When the hint is set to GL_ NICEST, a larger filter function may be applied causing more fragments to be generated and rendering to slow down.

No matter which line antialiasing method is used in your particular version of OpenGL, you can approximate either by choosing the right blend equation. The important point to remember is that antialiased lines and points are a form of transparent primitive. This requires blending to be enabled so that the incoming pixel fragment will be combined with the value already in the framebuffer, depending on the alpha value.

The best approximation of a one-pixel-wide quadrilateral is achieved by setting the blending factors to GL_ SRC_ALPHA (source) and GL_ ONE_MINUS_SRC_ALPHA (destination). To best approximate the lines of a stroke display, use GL_ ONE for the destination factor. Note that this second blend equation only works well on a black background and does not produce good results when drawn over bright objects.

As with all transparent primitives, antialiased lines and points should not be drawn until all opaque objects have been drawn first. Depth buffer testing should remain enabled, but depth buffer updating should be disabled using glDepthMaskGL_FALSE(GL_FALSE). Antialiased lines drawn with full depth buffering enabled produce incorrect line crossings and can result in significantly worse rendering artifacts than with antialiasing disabled when a lot of lines are drawn close together.

If the destination blend mode is set to GL_ ONE_MINUS_SRC_ALPHA there may be visible order dependent rendering artifacts if the antialiased primitives are not drawn in back to front order. There are no such order dependent problems with a setting of GL_ ONE, however. It is best to pick the method that best suits your particular application.

Incorrect monitor gamma settings are much more likely to become apparent with antialiased lines than shaded polygons. Broadcast television uses a gamma value of 2.22. The gamma value needed to correct most color CRTs is usually between 2.0 and 2.6. Some workstation manufacturers use values as low as 1.6 to enhance the perceived contrast of rendered images even though it produces a definite intensity nonlinearity in displayed images. Signs of insufficient gamma are ``roping'' of lines and moire patterns where many lines come together. Too much gamma produces a ``washed out'' appearance.

Antialiasing in color index mode is trickier because you have to load the color map correctly to get primitive edges to blend with the background color. When antialiasing is enabled, the last four bits of the color index indicate the coverage value. Thus, you need to load sixteen contiguous colormap locations with a color ramp ranging from the background color to the object's color. This technique only works well when drawing wireframe images, where the lines and points typically need to be blended with a constant background. If the lines and/or points need to be blended with background polygons or images, RGBA rendering should be used.


next up previous contents
Next: 9.2 Polygon Antialiasing Up: 9 Antialiasing Previous: 9 Antialiasing   Contents
2001-01-10