Some brief advice on how to get started doing interactive 3D graphics programming in C/C++

1. Learn to use OpenGL

If you're interested in doing interactive 3D graphics programming, a good first step would be to learn how to use a 3D rendering API (or library) that can exploit the hardware acceleration available on many computers today. The two popular alternatives for C/C++ are: OpenGL, and Microsoft's DirectX / Direct3D. Both of these libraries allow you to render z-buffered 3D geometry, composed of polygons or other primitives, in real time. (Note that neither of these libraries, however, are designed for doing ray tracing or global illumination rendering, which (at the time of writing -- 2004) cannot, typically, be done in real time or at interactive rates, and are typically implemented entirely in software.)

OpenGL is a descendant of Silicon Graphics' GL ("Graphics Language") library, is controlled by the OpenGL Architecture Review Board (ARB), and is supported on all major platforms (Microsoft Windows, various flavours of UNIX including linux, Mac OS, OS/2, and probably others). DirectX / Direct3D, however, is proprietary, is controlled by only one company, and is only supported on Microsoft Windows. I recommend you learn OpenGL rather than DirectX / Direct3D, so that you will be able to develop, share, and distribute your code on more platforms, and also to increase the longevity of your code.

Note that, although OpenGL can exploit the hardware acceleration available on many computer systems (assuming appropriate drivers are available and installed), hardware acceleration is not a prerequisite for working with OpenGL. In the unfortunate event that you must work or run your 3D code on a computer that has no hardware acceleration for 3D graphics, or that you don't have the appropriate drivers installed for your particular video card, you can still develop and test your 3D graphics code by using a library like Mesa, which is (roughly speaking) a free software-implementation of the OpenGL interface. Doing this does not hurt the portability of your code or prevent you from moving to a hardware accelerated platform at a later date, because OpenGL and Mesa use the same interface.

Also note that OpenGL is not just useful for 3D graphics. It's also a convenient cross-platform library for doing 2D raster graphics, and can be used to draw the widgets (buttons, scrollbars, menus, checkboxes, ...) of a 2D graphical user interface.

For a good introductory book on OpenGL, try OpenGL Programming Guide by Woo, Neider, Davis and Shreiner (the so-called "red book"). An online copy of this book appears to be here. There also used to be an online copy here, but it now seems to be gone. You might also try here or here

1.1. Obtaining and installing OpenGL

Microsoft Windows and many distributions of linux (such as Redhat) ship with support for OpenGL (or Mesa) -- i.e. library file(s) and C header file(s) -- meaning you often don't have to manually install it to use it. If you don't have OpenGL on your system, try downloading and installing Mesa, as it requires no special drivers and may be relatively easy to install.

2. Learn to use GLUT

Although OpenGL is cross-platform, OpenGL does not, by itself, provide enough functionality to make a 3D graphics program that is cross platform. OpenGL only allows you to draw graphics into a window. To first open a window, or subsequently retrieve input events from the windowing system, some other library must be used. A library that is native to the OS could be used for this (such as WIN32 on Windows, or Xlib on UNIX), however this would break the portability of your program's source code. Fortunately, there are cross-platform libraries designed specifically to complement OpenGL, that support the opening of windows and the retrieval of input events. The simplest of these is GLUT, which I use myself and recommend for beginners, and which is used in the example code given in the "red book" (see above). Versions of GLUT are available for all major platforms (Microsoft Windows, various flavours of UNIX including linux, Mac OS, OS/2, and possibly others). Alternatively, you may use a library like GLUI, GLOW, or Qt, all of which are more elaborate and more powerful cross-platform UI libraries that integrate nicely with OpenGL code and that also support widgets.

2.1. Obtaining and installing GLUT

Many distributions of linux (such as Redhat) ship with GLUT, in which case you don't have to manually install it to use it. GLUT can also be downloaded as a package for linux and installed fairly easily.

Microsoft Windows does not ship with GLUT; it must be installed to be used. Fortunately, manual installation of GLUT on Microsoft Windows is simple. Do a web search for: glut dll win. You'll probably find a webpage like or You'll need to download 3 files:

Depending on your needs, you may also want to install other related libraries on Windows, such as GLU.

You're now ready to start writing and compiling your first OpenGL + GLUT program.

3. (Optionally) Play with this sample OpenGL+GLUT Program

Here's a sample program that uses OpenGL, GLUT, and other very standard libraries (STL and POSIX). You may find it to be a useful example to learn from or modify.

If you plan to use OpenGL in many programs, or in a moderately large program, you'll benefit from having a few C++ utility classes that implement things like points, vectors, matrices, other geometric or mathematical objects, and perhaps a camera (i.e. viewpoint). Such classes can wrap around and hide many of the nitty gritty details of working with OpenGL, such as linear algebra and matrix stack manipulation. The sample program includes classes that implement a 3D vector, 3D point, 4x4 matrix, 3D ray, 3D axis-aligned box, plane, camera, and also has some utility routines for drawing circles, arrows, strings of text, and other things.

Rather than using the classes in the sample program, you may prefer to take the (more time-consuming and more fun) path of writing your own utility classes. This is commendable, and you'll learn a lot more writing your own classes. However, consider first looking at these tips for writing 3D graphics utility classes to inform your design.

3.1. Compiling and running the sample program

On UNIX/linux, unpackage and compile the program with

   cd example_opengl_glut_program
Then, browse over the README.TXT file, and run
Press and hold the ALT key and click-drag with the left mouse button to orbit.

If you use cygwin on Windows, you can compile the program almost the same way as on UNIX/linux. First make sure you have the gcc/g++, make, and opengl packages for cygwin, and you may possibly also need the freeglut package for cygwin (you can download all of these packages with cygwin's "setup.exe" installer). To compile the source code, you can use the Makefile that is supplied with it, after changing the definition of LIBS in the Makefile to

   LIBS=-lm -lglut32 -lglu32 -lopengl32
Note that the above flags for linking should be the last arguments passed to g++.

If you use Visual Studio C++ on Windows, then perform the following steps:

After successfully compiling the program, read the README.TXT file, and run the executable. Press and hold the ALT key and click-drag with the left mouse button to orbit.

Links -- possibly stale

OpenGL manual pages

GLUT home
more info/docs on GLUT

some history