This week I worked with texture mapping on a curved surface, texture mapping with lighting, and fog.
To map a texture onto a curved surface, the texture needs to be bound with a call to glBindTexture
within the same glPushMatrix ... glPopMatrix
block as the drawing code for the surface. Environment
variables also need to be set to allow mapping onto a curve. The code for setting these variables is as follows:
|
In the last few weeks, the textures on the robot's torso and face did not support lighting. This was
because lighting and shading only work on textures when the texture environment is in GL_MODULATE
or GL_BLEND
mode. GL_MODULATE
modulates the color of the texture with the background
color. GL_BLEND
blends the texture color with the background color or a user-specified color
array. Other environment modes disable lighting for mapped textures.
Fog in OpenGL turned out to be quite easy to implement. OpenGL has a built-in fog feature activated with the following code:
|
Key bindings
F1 - Switch texture on robot's torso.
F2 - Cycle through background scenes.
F3 - Switch fog on and off. Fog is on by default.
q - Exit program.