LightTorus is a C program illustrating the use of OpenGL. It is
intended to accompany the book 3D Computer Graphics: A mathematical approach
with OpenGL, by S. Buss, Cambridge University Press, 2003. However,
it can be used independently as well.
LightTorus draws a torus in a non-standard way, as a ribbon of quad
strips that wrap around the torus in one long strip. The C code consists of two
source files, LightTorus.c and LightTorus.h.
There are several options available for downloading this program:
Things to try out:
- Before running LightTorus, you should try out the simpler WrapTorus program. For a
simpler setting illustrating the use of lights and material properties, see SimpleLight.
- Compile and run the program. Test out the keyboard controls. The controls
j.-l. are new and not in WrapTorus.
- Press arrow keys (left, right, up and down) to make the torus rotate.
- Press "s" to single step the animation,
- Press "a" to start the animation running again without stopping. (Undoes
the "s" effect.)
- Press "r" to reset the torus back to its original orientation with no
- Press "0" (zero) to zero the velocity of the torus, but leave its position
- Press "W" to increase the number of wraps, "w" to decrease the
number of wraps.
- Press "N" to increase the number of segments per wrap. "n" to
decrease the number of segments per wrap.
- Press "q" to toggle between drawing quadrangles and triangles.
- Press "p" to toggle between rendering in filled polygon mode, and in wireframe
- Press "f" to toggle between flat shading and smooth shading.
- Press "0" (zero) and "1" (one) to toggle the lights (Light #0 and
light #1) off and on.
- Press "l" to toggle local mode off and on. This command switches between
having a local viewer and a positional light and having a non-local viewer (i.e.,
positioned at a point at infinity) and a directional light.
- Observe how the torus now looks three-dimensional in "filled polygon" mode.
(Keyboard control: "p".) This is a big improvement over the WrapTorus
program, and is caused by the use of material properties and Phong lighting.
- Try toggling the lights off and on. Observe the effects both diffuse lighting and
specular highlights. Why is the torus still visible when both lights are turned off?
(Ans: global ambient light.) Why does the torus look completely flat shaded, with no
three-dimensionality, when both lights are turned off?
- When toggling local mode off and on, observe how the specular highlights change.
This is due to the changes in the light vector l and and the view vector v.
- Experiment with increasing the resolution of the mesh (controls "N" and
"W"). At what point does the torus look smooth? You answer will
vary depending on whether you are in local mode, and whether the torus animation is