HowTo: Create Your First OpenGL Application

From Gravity
Jump to: navigation, search

Your first OpenGL program

From Visual Studio, create a new Project. There are several different types to choose from, but the one we want is Win32 Console Project (VS 6.0), or Win32 Project (VS .NET). If you were going to create the window and OpenGL context yourself, you would use a normal Win32 project, but since we're using GLUT, we want the console project. Pick a convenient location for the project, and give it a name (such as Lab1), then press OK (Figure 1).

VC NewProject.png
Figure 1 - New Project

If you're using Visual Studio 6, select Empty Project. If you're using Visual Studio .NET, select Application Settings on the left, then make the following settings (Figure 2):

  • Application type: Console Application
  • Add support for: uncheck all
  • Additional Options: Empty Project

VC ApplicationSettings.png
Figure 2 - Application Settings

Once the project is created, download sample.c and add it to your project. If you compile your program and get link errors, it is because you are missing the following libraries: glui32.lib, glut32.lib, opengl32.lib, and glu32.lib. To add them, go to Project->Settings, and click on Linker, Input on the left hand side (VS .NET) or the link tab (VS 6.0). Under additional dependencies (VS .NET) or Object/library modules (VS 6.0), add opengl32.lib glut32.lib glu32.lib (Figure 3). Now it should compile.

VC AdditionalDependencies.png
Figure 3 - Additional Dependencies

In order for your program to run, it needs access to glut32.dll. One way to do this is to put glut32.dll in the \system or \system32 path. In a lab environment like this one, you do not have access to these folders, so there is another method. Go back to c:\glut and make the folder c:\glut\bin. Copy glut32.dll into c:\glut\bin. Now minimize to your desktop.

  • Right click on My Computer and select Properties.
  • Click on the Advanced tab and select Environmental Variables
  • In the top box (User variables for...) edit Path (or creat it if it does not already exist). Add c:\glut\bin to the path. This will now look for dll dependencies in c:\glut\bin so your program can load glut32.dll.

Now execute your program, you should see a window with a button and a check box

Personal tools