OpenGL on Mac OS XUsing XCode
This will get you an XCode project with all of the necessary frameworks added to it.
- Make sure you have XCode installed. If you don't (it doesn't come installed on new Apple machines), you'll need to dig around on your supplied OS X CDs/DVDs. Usually it is on disc 2 of the install set. Install the whole thing.
- Fire up XCode and create a new project:
File:New Project
. - In the Assistant screen, scroll down to Command Line Utility and choose Standard Tool. Give it a name and a location. This will give you a barebones project without any of the Cocoa stuff included. You could, of course, use a more inclusive project option, but I'm talking barebones here.
- In the project window, Control+Click (or Right-click, if your mouse has more than one button...) and choose Add...:Existing Frameworks. You should get a file dialog that is already showing/System/Library. Just choose /System/LibraryFrameworks/OpenGL.framework, for the base OpenGL framework and GLU, or /System/Library/Frameworks/GLUT.framework, if you want GLUT.
- In your source files, be sure to include OpenGL/gl.h, OpenGL/glu.h, and/or GLUT/glut.h.
Using GNU tools
This will get you going on the command line. This ought to be easier if you plan on moving between operating systems.
coming soon!
Porting to/from OS X
OpenGL == cross-platform, right? Almost. Porting an existing OpenGL application to or from OS X is largely a matter of headers (I think...). For some unknown reason, OS X puts the headers in a different location in the include path than Windows and Linux (and probably a bunch of other *n?x OSes). Here's the skinny:
Header Description | Mac OS X | The Rest of the World |
GL - OpenGL Base | | |
GLU - OpenGL Utility | | |
GLUT - OpenGL Utility Toolkit | | |
The other headache(?) that you will come across if you are doing things on the command line is what switches to feed gcc
. The proper Mac switches are available above
, but what do you do if you want to move your app to Linux? Or, heaven forbid, Windows?
Well, for Linux, you will replace those short little -framework
flags with something like the following (stolen, unceremoniously, from the CS280: Real-time Graphics class website at UCSB):
-lglut -lGLU -lGL -L/usr/X11R6/lib/ -lXmu -lXi -lXext -lX11 -lXt
For Windows I have, admittedly, no idea.