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:
- Download GLUT
- Note: While this DLL works fine for me, some people have reported errors using it under
Visual Studio .NET 2005. If you have this problem, you may try the following:
- Try this modified version. (I have not tested this!)
- Recompile GLUT from source files with
Visual Studio .NET 2005.
- Try using FreeGLUT.
- IMPORTANT NOTE: If you use this, you must include all necessary files upon submission. I do not
use FreeGLUT under Windows, and I do not have it installed.
- Use an older version of Visual Studio.
- Unzip the file.
- Put the file "glut32.dll" into the system directory (Usually: "C:\WINDOWS\system32")
- If you don't have permission to move files into the system directory, have a copy of "glut32.dll"
in the same directory as your executable.
- Under Windows Vista, it appears that sometimes you are allowed to put DLLs into the system directory,
but without "registering" them somehow, you cannot use them. If you get error messages about missing
GLUT DLLs, put the "glut32.dll" in the same directory as your executable. Alternately, find out how
to register these DLLs and send me an e-mail!
- Put the file "glut.h" into the standard Visual C++ include directoy
- (This should be something like: "C:\Program Files\Microsoft Visual Studio.NET\Vc7\PlatformSDK\Include\gl")
- You've got the right directory if you see a copy of "gl.h"
- Put the file "glut32.lib" into the standard Visual C++ library directory
- (This should be something like: "C:\Program Files\Microsoft Visual Studio.NET\Vc7\PlatformSDK\lib")
- There should be lots of .lib files here, including "opengl32.lib" and "glu32.lib".
- 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:
- Menu: "Project -> (your-project-name) Properties"
- Tab: "Configuration Properties -> Linker -> Input"
- Under "Additional Dependancies", add "glut32.lib glu32.lib opengl32.lib"
- #include < GL/glut.h > in your program. Note this needs to come before you #include < GL/gl.h >.
- You should not include windows.h or any other Windows-specific header files, no matter what you may read
on random forum postings!
- 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)".
- 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)