OpenGL on Mac OS X

Using XCode

This will get you an XCode project with all of the necessary frameworks added to it.

  1. 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.
  2. Fire up XCode and create a new project: ​​File:New Project​​.
  3. 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.
  4. 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.
  5. 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

​#include <OpenGL/gl.h>​

​#include <GL/gl.h>​

GLU - OpenGL Utility

​#include <OpenGL/glu.h>​

​#include <GL/glu.h>​

GLUT - OpenGL Utility Toolkit

​#include <GLUT/glut.h>​

​#include <GL/glut.h>​

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.