You are on page 1of 1

Sample OpenGL Software

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. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

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

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

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:

converted by