Thursday, June 01, 2006

visual c++ 2005 and openGL

For my non-technical audience, scroll down and pretend this entry isn't here :)

I was trying to set up Visual C++ 2005 for OpenGL programming and I found absolutely nothing on the Web for 2005, so I'm publishing this quick and dirty guide to explain how to set up Visual C++ 2005 for basic OpenGL and Open GL Utility Toolkit (GLUT) programming. GLUT allows for a platform independent means of creating windows and registering callback functions to handle events. This allows one to run OpenGL-based programs without having to integrate Win32, MFC, or Windows Forms API calls (useful if one wants to test a concept without having to write all the Windows calls).

Download and Install GLUT for Win32
Windows comes with an Microsoft implementation of OpenGL, but does not come with a GLUT implementation. Nate Robins ported Mark Kilgard's original GLUT implementation to the Windows platform. Download the latest version of the binary, 3.7.6 at the time of this writing, from Nate Robins's GLUT for Win32 page.

The GLUT package comes with glut.h, glut.lib, and glut32.dll. Unzip these files and copy them into their proper respective locations, listed below.

glut.h → C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\gl

glut32.lib → C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib

glut32.dll → C:\WINDOWS\system32


Setting Up a Project in Visual Studio for OpenGL and GLUT
1. Launch Microsoft Visual Studio, start a new project (File → New → Project).

2. For the project type, select Visual C++ → Win32 → Win32 Console Application. Select the directory to save the project, preferably somewhere on C: drive and give the project an appropriate name.

3. Include the necessary headers in the primary source file (for compilation):
     #include "windows.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

4. Add the necessary libraries in the project settings Project → Project Name Properties, Configuration Properties → Linker → Input → Additional Dependencies (for linking):
     opengl32.lib
glu32.lib
glut32.lib

5. If the main function signature is defined as the former, replace it with the latter:
     int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char* argv[])

2 Comments:

At December 5, 2007 3:17 PM, Anonymous Anonymous said...

Just what I was looking for. Got it working in 5 minutes, thanks a lot;)

 
At September 12, 2008 12:26 PM, Anonymous Anonymous said...

Really fast and easy set up! Thank you for saving me hours of trying to figure this out!!!

 

Post a Comment

Links to this post:

Create a Link

<< Home