Tuesday, July 6, 2010

OpenGL/GLUT with C++ on Windows 7

Windows 7 comes with a dll for OpenGL, and most C++ compilers and IDE's come with library and header files for OpenGL too. But, if you've just begun learning OpenGL, then you are definitely going to need GLUT. Setting things up is a real pain, and can take quite some time. I had to struggle for a while, but then I found this awesome post on levelbylevel.com. It's like a step-by-step guide to set up GLUT and start working with it on CodeBlocks (with MinGW). It was a real lifesaver. I'm posting a breif summary here:
  • Get a C++ IDE with an OpenGL library and header file. CodeBlocks(with MinGW) or DevC++ will do.
  • Download GLUT and extract the zipped file.
  • Copy the file glut.dll into the system folder C:\Windows\System32 (VERY IMPORTANT: If you are using a 64-bit version of Windows, copy the file into C:\Windows\SysWOW64, otherwise it won't work).
  • Copy the file glut.h into the 'include\GL' folder in the C++ compiler folder. On DevC++, it is in the folder where DevC++ is installed, on CodeBlocks it is the MinGW folder inside the folder where CodeBlocks is installed.
  • Copy the file libglut32.a into the 'lib' folder in the C++ compiler folder.
  • Link the libraries 'opengl32' , 'glu32' and 'glut32' to the project in which you wish to use GLUT (how this is done depends on what IDE you are using).
  • You are now good to go.
 If you're looking for a good book to get started with OpenGL without going too deep into the math, try OpenGL SuperBible.