Installing OpenGL

You need to install an environment on your hardware where you can compile and run OpenGL programs. OpenGL is supported on most modern operating systems, but how to compile and link programs varies greatly. The description below assumes that you already have a compilation environment set up.

Before asking for help, look at the Troubleshooting hints to localize the problem rather than asking a meaningless question like It doesn't work.


OpenGL support is very easy to enable on current Linux distributions. For distributions derived from RedHat Linux, the libraries and header files are installed using the command

yum install freeglut-devel

Since GLUT depends on OpenGL and a number of other libraries, installing GLUT will trigger the dependencies needed to install everything else. For distributions derived from Debian such as Ubuntu, the installation command is

apt-get install freeglut3-dev

To compile and link your program on Ubuntu 14 based distros you need to explicitly grab every library using

gcc -o foo foo.c -lglut -lGLU -lGL -lm

I recommend that you use this full version even if not required on your system. Older distributions may put the files in /usr/X11R6, in which case you need to add -I and -L flags to pick up the header files and libraries.

Once installed, run the glxinfo program and look for direct rendering in the output. If the result is YES, then hardware support for OpenGL is working. If it is NO, some things are done in software and you may take a performance hit. Depending on your hardware, you may want to work on your X server. Specifically, the nVidia and AMD/ATI web sites contains updated drivers that result in improved performance over the stock Xorg drivers.

The compiz window manager (which is an OpenGL window manager) makes applications which use glutIdleFunc() run jerky unless you enable VSync. This seems to be an issue especially with newer Ubuntu installs.


The OS/X Darwin environment is based on OpenGL. Therefore any compilation environment for OS/X should already support compiling OpenGL programs.

To compile and link your program using the Apple SDK requires

gcc -o foo foo.c -framework GLUT -framework OpenGL

Note that under OS/X, the GLUT header files are in the subdirectory GLUT rather than the GL subdirectory. The following code works on OSX and Linux

#ifdef __APPLE__
#include <GLUT/glut.h>
#include <GL/glut.h>


Various Windows versions support OpenGL natively, but graphics card manufacturers often replace the native Windows OpenGL libraries with their own libraries that support specific features of their hardware.

Since most Windows environments do not contain a native compilation suite, installing the necessary header files and libraries differs depending on the compiler used. You may also need to install GLUT from Nate Robins.

Windows: MinGW

If you don't have a compiliation environment on Windows, you can install MinGW which provides the gcc compiler for Windows.

Download and install MinGW. Accept all the defaults, except that you also should install "make". After the installation is completed, change directories to C:\MinGW\bin and rename mingw32-make.exe to make.exe to avoid having to type mingw32-make every time you want to use make. You should also add C:\MinGW\bin to your PATH.

Finally, install GLUT by unzipping my version of GLUT into C:\MinGW. It will provide include\GL\glut.h and lib\libglut32cu.a needed to use GLUT. It also provides glut32.dll. Move glut32.dll to C:\windows\system32 so that the system can find this DLL at run time.

Note that my version of GLUT has been patched to provide glWIndowPos which otherwise would not be available on Windows systems which support OpenGL version 1.1.

To compile and link foo.c under MinGW you need

gcc -Wall -ofoo foo.c -lglut32cu -lglu32 -lopengl32

Windows: DevC++

Jeremy Salter provided this writup for installing OpenGL with DevC++.

Windows: Other

Your Windows system may provide OpenGL 1.1, which dates from 1995. This version will not contain the glWindowPos functions which I use a lot. You can provide the same functionality in software by including this code in your build. DO NOT include this code in what you submit, as it will result in a conflict in Linux or OSX systems. You do not need to install this code if you use the glut32cu library described above as this library already adds this code.

Troubleshooting hints

If you are having trouble getting the programs to compile, you may want to consider these things to determine if the problem is in your compiler, header files or linker/libraries.