Compiling OpenGL Progams Using Visual Studio

Windows does not include GLUT standard, like the lab machines in MLH 301 do. Thus, getting your OpenGL programs to compile and run is slightly more difficult. This used to be easy to explain and straightforward. For most people, these older and simpler instructions should still work. With new versions of Windows and Visual Studio, the instructions are getting a bit more complex.

However by following the following steps, you should be able to figure out how to make it work:

  1. Download GLUT
  2. Unzip the file.
  3. Put the file "glut32.dll" into the system directory (Usually: "C:\WINDOWS\system32")
  4. Put the file "glut.h" into the standard Visual C++ include directoy
  5. Put the file "glut32.lib" into the standard Visual C++ library directory
  6. Make sure your Visual C++ project links in the GLUT/gl/glu libraries. This can be a little difficult to find. In Visual Studio 2003 and 2005.NET, this is located in:
  7. #include < GL/glut.h > in your program. Note this needs to come before you #include < GL/gl.h >.
  8. You should not include windows.h or any other Windows-specific header files, no matter what you may read on random forum postings!
  9. If you get compilation errors because of multiple conflicting definitions of "exit()", then "stdio.h" and "glut.h" have been #include'd in the wrong order. You may fix this by either reordering your #include files (the preferred way) or by adding "#define GLUT_DISABLE_ATEXIT_HACK" to glut.h on the line immediately after the first "#if defined(_WIN32)".
  10. If you happen to have a 64-bit version of Windows and Visual Studio, make sure you compile a 32-bit executable.

NOTE: Later in the course, you may also need to install GLEW. Follow the same directions: install the DLLs into the system directory, the header files in the include directory, and the library files into the lib directory.


Last Modified: Thursday, August 13, 2007

Chris Wyman (cwyman@cs.uiowa.edu)