SimpleAnim is sample C code illustrating the use of OpenGL. It
is intended to accompany the book 3D Computer Graphics: A mathematical
approach with OpenGL, by Samuel R. Buss, Cambridge University Press, 2003.
However, it can be used independently as well.
SimpleAnim rotates three overlapping triangles. It
consists of two source files, SimpleAnim.c and SimpleAnim.h.
There are several options available for downloading this program:
Things to try out:
- Compile and run the program. Try out the keyboard controls. Pressing
"r" starts and stops the animation. Pressing "s" performs single
steps of the animation. The up and down arrows control the speed of the
- Observe aliasing problems with the borders of the triangles. To do this enlarge
the window for a better view. Then slow down the rotation until the triangles are
turning slowly. Along the edges of the triangles you should see jagged edges and/or
movement of pixels. The narrow tips of the triangles may look very "jumpy"
when observed carefully at slow rotation rates.
- This program uses double buffering in order to make the animation look good.
Experiment by changing the program to use single buffering. To use single buffering,
change the parameter GLUT_DOUBLE to GLUT_SINGLE and
comment out the call to glutSwapBuffers(). How does the animation
look in single buffer mode?
- Near the beginning of the drawScene routine, the current angle is
clamped to be less than 360 degrees. What would go wrong if this was removed from
the code. Try making this change. What goes wrong? (To make things go
wrong faster, run the simulation at a high rate for a little while, then at a low rate:
you need to run it long enough to let overflow/underflow errors become significant.)
Is it what you expected? Can you explain what is happening? Similarly,
what goes wrong if the value of AnimateIncrement is allowed to get too
large? (Or too small?).
- Understand how the glTranslatef and glRotatef work.
These commands are described in chapter 2 of the book.