Sample OpenGL Software

This page is somewhat out-of-date. It uses examples from legacy (immediate mode) OpenGL. For examples using modern OpenGL with shader programs, please to the web page of OpenGL software supporting the planned second edition of the book.

The OpenGL programs below are intended to accompany the book 3D Computer Graphics: A mathematical approach with OpenGL, by Sam Buss, Cambridge University Press, 2003.   However, they can be used independently as well.  These are short C programs that illustrate the use of some of the basic features of OpenGL.   There is also a ray tracing software package that accompanies the same book.

The programs are supplied with Visual C++ 6.0 project and workspace files; however, the source files should work with other compilers and on other systems as well.  You will need to have OpenGL and GLUT installed (the header files to compile and the object libraries to run the programs).

  1. SimpleDraw shows how to draw points, lines, line strips and line loops.  
  2. SimpleAnim is a simple example of double buffering and animation.
  3. Solar builds an animated solar system (a standard OpenGL example).
  4. ConnectDots shows how to capture mouse clicks in OpenGL using GLUT and draw a series of straight lines connecting points chosen with mouse clicks.
  5. SimpleLight shows two spheres lit by a point light source.  Illustrates light properties and material properties.  The light is animated.
  6. WrapTorus builds a torus from a single, long quadstrip, wrapping around like a ribbon.
  7. LightTorus adds lighting and material properties to WrapTorus.
  8. TextureBMP has code from reading a texture from a .bmp bitmap file, and applies it to a quadrangle.
  9. FourTextures shows how to manage multiple textures.
  10. TextureTorus puts a texture on the torus from LightTorus.
  11. GluCylinders shows generate cylinders and slant cylinders with gluQuadrics (these shapes are not supported by the GLUT API.)
  12. SimpleNurbs draws a rational Bezier patch.
  13. RgbImage routines to support reading and writing bitmap (.bmp) files.
  14. glrnRenderNormals routines that draw normals on surfaces for debugging OpenGL programs.

For Unix/Linux users:  Sample makefiles for compiling and linking SimpleDraw are provided here.  For the other programs, make the obvious changes to the makefile by listing the .c source files on the compiler command line in the correct order.  The makefiles have been tested under Solaris Unix only (if anyone gives me makefiles for other systems, I could post them too.)  There are two makefiles: (a) a makefile which uses cc, and (b) a makefile which uses gcc and (c) A CMake configuration file, courtesy of Mick Beaver (

Visual Studio 2010 users:  The projects above are Visual Studio C++ version 6.0, but should work with the new Visual Studio 2010 compiler too. 

Visual Studio.NET users:  The projects above are Visual Studio C++ version 6.0, but should work with the subsequent .NET compilers too.  There is a potential problem with incompatibilities between the exit() function prototypes used by C and GLUT.    These apparently can be avoided by being sure you do not #include the file stdlib.h after you #include the glut.h file.  However, if you still get error messages about the exit() function prototype or from stdlib.h, you can also try using my modified version of glut.h that works with the more recent .NET compiler.   

Obtaining GLUT.  The programs above all depend on OpenGL and GLUT. 
    If you are using Visual C++, you probably have OpenGL already installed, but it may not come with GLUT.  The official page for downloading the latest version of GLUT for PC's is Nate Robin's page    You will get files glut32.dll and glut32.lib and glut.h.   These should be installed on your Windows PC in the same directories as the other OpenGL files --- to find these directories do a "Seach" or "Find Files" for glu32.dll and glu32.lib and glu.h.  It is also possible to install these files locally if you do not have the file access permissions to write to system directories.
    You can also use GLUT with other compilers and operating systems (see the preface to the book).
    More information on GLUT can be found at
    Visual Studio .NET users may wish to get my custom modified version of glut.h.  (To let GLUT work Visual Studio.NET without needing to disable the "at exit" hack.)

Bug reports or other problems: