WrapTorus 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.
WrapTorus 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, WrapTorus.c and WrapTorus.h.
There are several options available for downloading this program:
Things to try out:
- Compile and run the program. Test out the keyboard controls.
- 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
- Observe how bad the torus looks in "filled polygon" mode. (Keyboard control:
"p".) This will be improved by the LightTorus program
with the addition of material properties and Phong lighting.
- Examine the source code to see how the torus is generated. In particular, note
that integer variables are used to control the loops that draw the vertices on the torus,
and we are careful when revisiting a vertex to calculate the x,y,z coordinates of the
vertex by exactly the same floating point calculation as the first time. This avoids
having small, pixel-size holes in the torus, as can occur due to floating point roundoff
(see the last section of Chapter 2 of the above book).