Lesson 0a: Getting OpenGL Set Up on Windows

This lesson will explain how to get OpenGL and GLUT set up on Windows. We'll use the Visual C++ Express 2005 IDE to edit, compile, and run our programs. Visual C++ Express is a free IDE. To use it, you will have to register, which is free, within 30 days. You can use another IDE if you prefer, but getting it set up will be a little different.

Downloading and Installing

First, download and install the necessary software using the following instructions:

  1. Download Visual C++ Express and the Microsoft Platform SDK from the Microsoft website. Note that when you download the SDK, it may say something about Windows Server. Don't worry about that; it'll install just fine on any modern version of Windows.
  2. Install Visual C++ and the SDK.
  3. Download the OpenGL installer from here and the GLUT binary from here.
  4. Run the OpenGL installer.
  5. Extract GLUT to the directory of your choice. You can do this by creating a new directory, locating and opening the ZIP file using Windows Explorer, and copying the files to the new directory using copy-paste. Alternatively, you can use a free program like WinZip to extract GLUT.
  6. In the directory to which you extracted GLUT, make two folders, one called "include" and one called "lib". In the "include" folder, create another folder called "GL", and move glut.h to that folder. Move all of the other files that you extracted for GLUT into the "lib" folder.
  7. Run Visual C++ Express. Go to Tools -> Options, then Projects and Solutions -> VC++ Directories. Note where it says "Show directories for". You'll want to change the directories for include files by adding "x\include", "y\include", and "z\Include" and to change the directories for library files by adding "x\lib", "y\lib", and "z\Lib", where "x" is the folder where you installed OpenGL, "y" is the folder where you extracted GLUT, and "z" is the folder where you installed the Microsoft Platform SDK.
  8. Change your PATH environment variable as follows: go to the control panel, and go to System. Go to the "Advanced" tab and click on "Environment Variables". Find the "PATH" (or "Path") variable. Change it by adding ";x\lib;y\lib;z\Lib" (without the quotes) to the end of it, where again, "x", "y", and "z" are the folders where you installed OpenGL, GLUT, and the Microsoft Platform SDK. Make sure there are no spaces before or after the semicolons.
  9. Reboot your computer, so that Windows will recognise the changes to the PATH environment variable.

Compiling and Running the Test Program

To make sure that everything was set up correctly, we're going to see if we can get a test program to work.

  1. Download this test program and extract it somewhere on your computer.
  2. Run Visual Studio C++. Go to File -> New -> Project From Existing Code.
  3. Click next to indicate that you are making a Visual C++ project.
  4. Set the project file location to the folder to which you extracted the test program. Enter in a name for your project (such as "cube") and click next.
  5. Change the project type from "Windows application project" to "Console application project", and click next.
  6. Click next, then click finish to finish creating the project.
  7. Go to Project -> Properties. Click on Configuration Properties. Click the "Configuration Manager" button in the upper-right corner. Change the "Active solution configuration" from "Debug" to "Release". Click close, then click OK.
  8. In Project -> Properties, go to Configuration Properties -> General. Where it shows the output directory as "Release", backspace the word "Release", and click OK. This makes Visual C++ put the executable in the same directory as the source code, so when our program needs to open a file, it looks for it in that directory. In this case, the program will have to load in an image file called "vtr.bmp".
  9. Go to Build -> Build project_name to build your project.
  10. There should be two warnings about ignoring /INCREMENTAL. You don't have to, but if you want, you can fix them as follows. In Project -> Properties, go to Configuration Properties -> Linker, and change "Enable Incremental Linking" from "Yes (/Incremental)" to "No (/Incremental:No)".
  11. Run the program by going to Debug -> Start Without Debugging. If all goes well, the test program should run.

Note that you'll have to set up a project every time you want to work on a program from my site, so you'll have to repeat steps 1 - 11 above.

I'd like to point out a couple of things about the program. First of all, notice that the project has a file called "Makefile". It's not used on Windows; it's only needed for Linux, Mac OS X, and other UNIX-based operating systems. But Visual C++ will automatically ignore the file, so you don't have to worry about removing it from the project.

Secondly, take a look at main.cpp. Notice that the include directives for OpenGL appear after the #include directives for the normal C++ include files. If we had them in the opposite order, because of the Windows download that I recommended for GLUT, you'd get a compiler error. So make sure that the include files for the standard C++ stuff appear before the include files for OpenGL.

Whew! We've finished setting up OpenGL. Now we're ready to learn how to program in 3D.

Next is "Part 1: The Basics".