Applying Secondary Color after Texturing (Texture Mapping) (OpenGL Programming)

While applying a texture to a typical fragment, only a primary color is combined with the texel colors. The primary color may be the result of lighting calculations or glColor*().

After texturing, but before fog calculations, sometimes a secondary color is also applied to a fragment. Application of a secondary color may result in a more realistic highlight on a textured object.

Secondary Color When Lighting Is Disabled

If lighting is not enabled and the color sum mode is enabled (by glEnable(GL_COLOR_SUM)), then the current secondary color (set by glSecondaryColor*()) is added to the post-texturing fragment color.

void glSecondaryColorijb s i f d ub us u\)(TYPE r, TYPE g, TYPE b);t void glSecondaryColor3{b s i f d ub us ui}v(const TYPE *values);

Sets the red, green, and blue values for the current secondary color. The first suffix indicates the data type for parameters: byte, short, integer, float, double, unsigned byte, unsigned short, or unsigned integer. If there is a second suffix, v, then values is a pointer to an array of values of the given data type.

glSecondaryColor*() accepts the same data types and interprets values the same way that glColor*() does.colors may also be specified in vertex arrays.

Secondary Specular Color When Lighting Is Enabled

Texturing operations are applied after lighting, but blending specular highlights with a texture’s colors usually lessens the effect of lighting. As discussed earlier , you can calculate two colors per vertex: a primary color, which consists of all nonspec-ular contributions, and a secondary color, which is a sum of all specular contributions. If specular color is separated, the secondary (specular) color is added to the fragment after the texturing calculation.


Note: If lighting is enabled, the secondary specular color is applied,regardless of the GL_COLOR_SUM mode, and any secondary color set by glSecondaryColor*() is ignored.

Next post:

Previous post: