Running GLUT Programs

Below is information about compiling and executing C/C++ programs that use Mark Kilgard’s OpenGL Utility Toolkit (GLUT), on various operating systems.

If you have other helpful information on this topic, please let me know.

MacOS

GLUT comes pre-installed on Apple’s Xcode development environment, so nothing special needs to be done to compile and run GLUT programs.

Note, however, that Apple puts the OpenGL and GLUT headers in nonstandard places. The following preprocessor directives will include the GLUT headers correctly on just about any system.

#ifndef __APPLE__
# include "GL/glut.h"
#else
# include "GLUT/glut.h"
#endif

If you are using something other than Xcode on MacOS, and GLUT is not installed (and you cannot figure out how to install it), let me know, and I might be able to help.

Linux

If you are using Ubuntu, or any other Debian-based Linux distribution, then, using your package manager (apt-get, Synaptic, etc.), install the package freeglut3-dev. To compile a GLUT program, you need to link with the GL, GLU, and glut libraries. So, for example, here is how I would compile the program sample2d.cpp, using the command line.

g++ sample2d.cpp -o sample2d -lGL -lGLU -lglut

Note: Watch out for the capitalization of the library names.

If you are using a Linux distribution that is not Debian-based, then you probably know a lot more about installing than I do. So: install freeglut (See “Links”, below), and use it as above.

Windows

To compile a GLUT program, GLUT needs to be installed. It may be already; to find out, try to compile and execute a GLUT program. If the header glut.h is not found, then GLUT is not installed, and you (or someone) will need to install it.

I recommend installing the “freeglut” package, an updated version of GLUT. You will need to install all of the following files, which can be downloaded from the freeglut site (see “Links”, below).

Headers   glut.h, freeglut.h, freeglut_std.h, freeglut_ext.h
Static Library   freeglut.lib
Dynamic Library   freeglut.dll

Once the installation is complete, compile and run a GLUT program like any C/C++ program.

Where you put these files depends on whether or not you have write access to system directories.

If You Have Write Access to System Directories

The header files go in the same place as the OpenGL headers (gl.h and glu.h). This should be a folder called “GL”, in the main directory for your compiler’s include files. Searching for gl.h will probably get you the right directory. For example, on my (ancient) Visual Studio installation, the directory is the following.

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\GL

The static library goes in the same place as the OpenGL library files. As above, searching for OpenGL32.lib will probably get you the right directory. On my Visual Studio installation, the directory is the following.

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib

The dynamic library goes in the system directory where DLLs are kept (look around inside C:\WINDOWS).

If You Do NOT Have Write Access to System Directories

The header files should go in a folder called “GL” that the compiler knows to look in. I put the GL folder in the same directory as my source code. Then I told the compiler to look for include files in the same directory as my source code. (Back in Visual Studio 2003, I did this by going to the “Project” menu and choosing “Properties...”. Then I selected “Configuration Properties : C/C++ : General” and added the proper directory to the “Additional Include Directories” line. This is done by clicking on the “...” button on the right, and, in the next dialog, clicking the new folder button and then “...” again; then choose the directory with your source code in it.)

The static and dynamic library files can probably go in the same directory as your source code. (On some systems the dynamic library may need to go in the directory that the executable is stored in.)

Links


Running GLUT Programs / Updated: 31 Aug 2011 / Glenn G. Chappell / ggchappell@alaska.edu