If you’ve seen my last post, you’re aware that I’ve been playing with OpenGL and GLUT for a uni subject. As I like to straddle the OS fence and use a mixture of Windows Vista x64, Windows XP and Mac OS X 10.5, I like to have platform independent solutions to problems. The latest little issue I’ve come across regarding GLUT apps is that GLUT on the Mac has a different include. To include GLUT in a project for the mac, you must use the following:
In order to cut code that will compile successfully on either platform we can use optional includes with the
#endif preprocessor directives. Props to “kainjow” for providing this information in his/her forum post. Here’s how:
All this does is say “if we’re running on an Apple machine,
include GLUT/glut.h, otherwise
include GL/glut.h. Now to actually learn OpenGL/GLUT…
I’ve recently had to install freeglut as part of a uni subject and ran across an issue due to the fact that I’m running Vista x64 and wanted to dynamically link freeglut against anything I develop during the semester. First of all, building freeglut (version 2.4.0) was problem free. I simply opened
freeglut.dsw (in the root directory of the freeglut download) in Visual Studio 2005 (VS2005), agreed to convert the project files to a newer format, and then built the solution. An additional step I took, which may be completely unnecessary, was to change the build type from Debug to Release. Both build types built fine, but I used the release versions as I doubt I will be debugging freeglut. Also note that I compiled this as the default 32-bit, not 64-bit, as I’m building 32-bit GLUT apps for compatibility.
Once this was done, I followed the info in
README.win32 (in the freeglut directory) and copied the files to the relevant directories. The specific directories I used for a Vista x64 system with VS2005 were as follows:
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\Include\gl.
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\Lib. Note that the correct destination should already contain
- Now here’s the part that caused me problems: copy
C:\Windows\SysWOW64 and NOT
C:\Windows\System32 as you might expect, given that it’s a 32-bit library being used in 32-bit projects
Once the files are in place, you should be ready to use freeglut in your apps. To do so, simply include freeglut as follows:
As you can see, we’re referencing
glut.h and not
freeglut.h. My guess is that this is done to maintain platform independence if your code was being built by a different incarnation of GLUT. For example I used this method to build and run the test app provided by my lecturer (unchanged), who uses the original GLUT.
***UPDATE 2009-02-27 ***
I copied the files I built on my Vista x64 machine to a 32-bit install of XP SP3 on my laptop and GLUT worked fine. The only difference to the above instructions (obviously aside from not building freeglut again) is to copy
C:\Windows\System32. I’ve also put together a zip package of my build for anybody who wants to avoid building themselves.