OpenGL Distilled

A.3. Fog

The fog feature, available since OpenGL version 1.0, blends a fragment color with a fog color based on the fragment distance from the eye. In versions 1.4 and later, applications can explicitly set fog-coordinate values to further control blending between the fragment and fog colors. Applications commonly use the fog feature for depth cueing and atmospheric effects.

To use the fog feature:

  1. At init time, enable fog by calling glEnable( GL_FOG ).

  2. The default fog color is black. To set a different fog color, call glFogfv ( GL_FOG_COLOR, color ), where color is an array of four GLfloats.

  3. You'll probably also want to adjust the default fog density. By default, OpenGL completely fogs a fragment if its eye-coordinate space distance is greater than 1.0. Make the fog less dense by setting a fog density value less than 1.0, such as glFogf( GL_FOG_DENSITY, .02f ).

For more information on fog, such as changing the fog equation and setting fog coordinates per vertex, see Chapter 6, "Blending, Antialiasing, Fog, and Polygon Offset," of OpenGL® Programming Guide and "glFog" in OpenGL® Reference Manual.

Категории