Using GLUT and OpenGL on Mac OS X

Q: How can I use GLUT on Mac OS X?

A: GLUT is available on Mac OS X through the GLUT framework. It is installed with every install of Mac OS X. For more information about frameworks, please see Introduction to Framework Programming Guide.

Note: Although GLUT is available on Mac OS X, Apple recommends OpenGL developers use the Cocoa-based NSOpenGL classes for window creation, because the NSOpenGL classes provide interfaces to other APIs on Mac OS X such as Core Image, Core Animation, etc.

To use GLUT on Mac OS X, you need to include the OpenGL and GLUT headers in a form of #include <framework name/header name.h>.

Listing 1: Include the OpenGL and GLUT headers

#include <OpenGL/gl.h>

#include <OpenGL/glu.h>

#include <GLUT/glut.h>

You also need to link your project to the OpenGL and GLUT frameworks. If you are using Xcode to build your project, select Add to Project under the Project menu, then select and add OpenGL.framework and GLUT.framework under /System/Library/Frameworks.

If you want to build your project from the command line or a make file, link the frameworks as shown in the following listing.

Listing 2: Build and link a GLUT program (glutapp) from the command line or a make file

cc -framework GLUT -framework OpenGL -framework Cocoa glutapp.c -o glutapp

For a GLUT sample that builds in Xcode, you may refer to GLUTBasics. This simple GLUT example shows the use of standard callbacks and camera control. It is good starter code to base your own projects on.

Cocoa-based NSOpenGL is recommended over GLUT for window creation on Mac OS X. When you are ready to move up from GLUT to NSOpenGL, please see the Cocoa OpenGL sample. This sample demonstrates using NSOpenGL to setup windows for drawing and to handle user events.

Document Revision History

Date Notes
2008-10-13 First Version

Posted: 2008-10-13


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.