Texturing Modes and Lighting


In OpenGL, there are three texturing modes for different rendering types. Modes are defined by a function known as glTexEnvi :
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_MODE, mode);

The default mode modulates lighting and color information with the texture image. It is the most used mode in 3D games. The variable for this is GL_MODULATE.

Another mode only uses the texture image where lighting and color information will not change the texture’s appearance. Reflection mapping is a case where this mode is used; special effects with multi-pass rendering is another example. The variable for this is GL_DECAL.

The third mode blends texture images with texture color, lighting as well as color information. The variable for this is GL_BLEND. You can set the texture color under the GL_BLEND mode using the glTexEnvfv function, as such :

GLfloat rgba[4];
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_COLOR, rgba);

You can also apply light sources to textures to further enhance realism but lighting effects can only be applied to GL_MODULATE and GL_BLEND modes and not GL_DECAL mode. With lighting effects, you can experiment with such things as specular highlighting. Specular highlighting is akin to adding "gloss" to an object. It is a form of multitexturing where a scene is drawn twice, once without any texturing and then drawn again with textures to arrive at the final scene. For example, you start by having no lighting except for the specular components of an object and draw the object without any texturing. Then you enable the GL_BLEND mode as well as specifying it to add the textures with normal lighting.