# glFog

## Name

glFog — specify fog parameters

## C Specification

 void glFogf( GLenum pname, GLfloat param);
 void glFogi( GLenum pname, GLint param);

## Parameters

pname

Specifies a single-valued fog parameter. GL_FOG_MODE, GL_FOG_DENSITY, GL_FOG_START, GL_FOG_END, GL_FOG_INDEX, and GL_FOG_COORD_SRC are accepted.

param

Specifies the value that pname will be set to.

## C Specification

 void glFogfv( GLenum pname, const GLfloat * params);
 void glFogiv( GLenum pname, const GLint * params);

## Parameters

pname

Specifies a fog parameter. GL_FOG_MODE, GL_FOG_DENSITY, GL_FOG_START, GL_FOG_END, GL_FOG_INDEX, GL_FOG_COLOR, and GL_FOG_COORD_SRC are accepted.

params

Specifies the value or values to be assigned to pname. GL_FOG_COLOR requires an array of four values. All other parameters accept an array containing only a single value.

## Description

Fog is initially disabled. While enabled, fog affects rasterized geometry, bitmaps, and pixel blocks, but not buffer clear operations. To enable and disable fog, call glEnable and glDisable with argument GL_FOG.

glFog assigns the value or values in params to the fog parameter specified by pname. The following values are accepted for pname:

GL_FOG_MODE

params is a single integer or floating-point value that specifies the equation to be used to compute the fog blend factor, $f$. Three symbolic constants are accepted: GL_LINEAR, GL_EXP, and GL_EXP2. The equations corresponding to these symbolic constants are defined below. The initial fog mode is GL_EXP.

GL_FOG_DENSITY

params is a single integer or floating-point value that specifies $density$, the fog density used in both exponential fog equations. Only nonnegative densities are accepted. The initial fog density is 1.

GL_FOG_START

params is a single integer or floating-point value that specifies $start$, the near distance used in the linear fog equation. The initial near distance is 0.

GL_FOG_END

params is a single integer or floating-point value that specifies $end$, the far distance used in the linear fog equation. The initial far distance is 1.

GL_FOG_INDEX

params is a single integer or floating-point value that specifies $i f$, the fog color index. The initial fog index is 0.

GL_FOG_COLOR

params contains four integer or floating-point values that specify $C f$, the fog color. Integer values are mapped linearly such that the most positive representable value maps to 1.0, and the most negative representable value maps to $-1.0$. Floating-point values are mapped directly. After conversion, all color components are clamped to the range $0 1$. The initial fog color is (0, 0, 0, 0).

GL_FOG_COORD_SRC

params contains either of the following symbolic constants: GL_FOG_COORD or GL_FRAGMENT_DEPTH. GL_FOG_COORD specifies that the current fog coordinate should be used as distance value in the fog color computation. GL_FRAGMENT_DEPTH specifies that the current fragment depth should be used as distance value in the fog computation.

Fog blends a fog color with each rasterized pixel fragment's post-texturing color using a blending factor $f$. Factor $f$ is computed in one of three ways, depending on the fog mode. Let $c$ be either the distance in eye coordinate from the origin (in the case that the GL_FOG_COORD_SRC is GL_FRAGMENT_DEPTH) or the current fog coordinate (in the case that GL_FOG_COORD_SRC is GL_FOG_COORD). The equation for GL_LINEAR fog is

The equation for GL_EXP fog is

The equation for GL_EXP2 fog is

Regardless of the fog mode, $f$ is clamped to the range $0 1$ after it is computed. Then, if the GL is in RGBA color mode, the fragment's red, green, and blue colors, represented by $C r$, are replaced by

Fog does not affect a fragment's alpha component.

In color index mode, the fragment's color index $i r$ is replaced by

## Notes

GL_FOG_COORD_SRC is available only if the GL version is 1.4 or greater.

## Errors

GL_INVALID_ENUM is generated if pname is not an accepted value, or if pname is GL_FOG_MODE and params is not an accepted value.

GL_INVALID_VALUE is generated if pname is GL_FOG_DENSITY and params is negative.

GL_INVALID_OPERATION is generated if glFog is executed between the execution of glBegin and the corresponding execution of glEnd.

## Associated Gets

glIsEnabled with argument GL_FOG

glGet with argument GL_FOG_COLOR

glGet with argument GL_FOG_INDEX

glGet with argument GL_FOG_DENSITY

glGet with argument GL_FOG_START

glGet with argument GL_FOG_END

glGet with argument GL_FOG_MODE