Contents / Previous / Next


Texture Functions: glTexEnv*()

The texturing function operates on selected components of the texture and the color values that would be used with no texturing.

The values in the texture map can be painted directly on the surface being rendered or the texture map can be modulated with the color that the surface would be rendered without texturing, or it can be blended with the original color of the surface.

You choose one of four texturing functions by supplying the appropriate arguments to glTexEnv*() to set the current texturing function:

void glTexEnv{if}(GLenum target, GLenum pname, TYPEparam);

void glTexEnv{if}v(GLenum target,GLenumpname, TYPE*param); 

target must be GL_TEXTURE_ENV.

If pname is GL_TEXTURE_ENV_MODE,
param can be GL_DECAL, GL_REPLACE, GL_MODULATE, or GL_BLEND, to specify how texture values are to be combined with the color values of the fragment being processed.

If pname is GL_TEXTURE_ENV_COLOR,
param is an array of four floating-point values representing R, G, B, and A components. These values are used only if the GL_BLEND texture function has been specified as well.

Example:

 gl.glTexEnvf( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE );

With the replacement texture function (similar to decal), the fragments' component values are either replaced or left alone.

For modulation, the fragment's color is modulated by the contents of the texture map. If the base internal format is GL_LUMINANCE, GL_LUMINANCE_ALPHA, or GL_INTENSITY, the color values are multiplied by the same value, so the texture map modulates between the fragment's color (if the luminance or intensity is 1) to black (if it's 0). For the GL_RGB and GL_RGBA internal formats, each of the incoming color components is multiplied by a corresponding (possibly different) value in the texture. If there's an alpha value, it's multiplied by the fragment's alpha. Modulation is a good texture function for use with lighting, since the lit polygon color can be used to attenuate the texture color. Most of the texture-mapping examples in the color plates use modulation for this reason. White, specular polygons are often used to render lit, textured objects, and the texture image provides the diffuse color.

With the decal texture function for the RGBA internal format, the fragment's color is blended with the texture color in a ratio determined by the texture alpha, and the fragment's alpha is unchanged. You use the decal texture function in situations where you want to apply an opaque texture to an object - if you were drawing a soup can with an opaque label, for example. The decal texture function also can be used to apply an alpha blended texture, such as an insignia onto an airplane wing.

The blending texture function is the only function that uses the color specified by GL_TEXTURE_ENV_COLOR. The luminance, intensity, or color value is used like an alpha value to blend the fragment's color with the GL_TEXTURE_ENV_COLOR.


Internal Textures Formats and Blending

The Tables show how the texturing function and base internal format determine the texturing application formula used for each component of the texture. There are six base internal formats (the letters in parentheses represent their values in the tables): GL_ALPHA (A), GL_LUMINANCE (L), GL_LUMINANCE_ALPHA (L and A), GL_INTENSITY (I), GL_RGB (C), and GL_RGBA (C and A). Other internal formats specify desired resolutions of the texture components and can be matched to one of these six base internal formats.

A subscript of t indicates a texture value, f indicates the incoming fragment value, c indicates the values assigned with GL_TEXTURE_ENV_COLOR, and no subscript indicates the final, computed value.
Multiplication of a color triple by a scalar means multiplying each of the R, G, and B components by the scalar; multiplying (or adding) two color triples means multiplying (or adding) each component of the second by the corresponding component of the first.

Replace and Modulate Texture Function

Base Internal Format

Replace Texture Function

Modulate Texture Function

GL_ALPHA

C = Cf, A = At

C = Cf, A = AfAt

GL_LUMINANCE

C = Lt, A = Af

C = CfLt, A = Af

GL_LUMINANCE_ALPHA

C = Lt, A = At

C = CfLt, A = AfAt

GL_INTENSITY

C = It, A = It

C = CfIt, A = AfIt

GL_RGB

C = Ct, A = Af

C = CfCt, A = Af

GL_RGBA

C = Ct, A = At

C = CfCt, A = AfAt

Decal and Blend Texture Function

Base Internal Format

Decal Texture Function

Blend Texture Function

GL_ALPHA

undefined

C = Cf, A = AfAt

GL_LUMINANCE

undefined

C = Cf(1-Lt) + CcLt, A = Af

GL_LUMINANCE_ALPHA

undefined

C = Cf(1-Lt) + CcLt, A = AfAt

GL_INTENSITY

undefined

C = Cf(1-It) + CcIt, A = Af(1-It) + AcIt,

GL_RGB

C = Ct, A = Af

C = Cf(1-Ct) + CcCt, A = Af

GL_RGBA

C = Cf(1-At) + CtAt, A = Af

C = Cf(1-Ct) + CcCt, A = AfAt