Sunday, April 24, 2011

Getting started with OpenGL on Windows

This post describes how to set up OpenGL in Windows. It uses Microsoft Visual Studio 2008 Professional Edition, and has been applied to Windows 7 Home Premium and Windows XP x64 SP2.

The first thing to do is download GLUT. From there you reach GLUT for Windows, which is what you need to download. The zip file contains glut32.dll, glut32.lib and glut.h, which you need to place in their correct places. glut32.dll needs to go in C:\WINDOWS\system (system32 won't work, and neither will placing it with your executable). glut32.lib needs to go in Visual Studio's lib folder (C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib\gl - you will need to create the gl folder), and glut32.h goes in the include folder (C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include).

Good, so now we set up a C++ project to try it out. Launch Visual Studio 2008. Go to File -> New -> Project... and create a Visual C++ project (Visual C++ -> General -> Empty Project). So now the project has been created but it is still empty so you still see the VS2008 start page. Go to the Project Properties (either by right clicking on the project in Solution Explorer and selecting Properties, or via the Project menu then Properties).

Set the Configuration field at the top left to All Configurations. In the treeview, go into Configuration Properties -> Linker -> Input. In Additional Dependencies, insert "opengl32.lib glu32.lib glut32.lib" (without quotes, as is, separated only by spaces). glaux.h is deprecated so you can just leave it out.

Finally, create a main.cpp file (Add -> New Item..., then C++ file; name it main.cpp), paste some sample code, and press F5 to run it.

 That's it. Hopefully this saved you the frustration I went through during the initial setup of OpenGL.

No comments:

Post a Comment