Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Using GLUT and OpenGL on OS X
Q: How can I use GLUT on OS X?
A: GLUT is available on OS X through the GLUT framework. It is installed with every install of OS X. For more information about frameworks, please see Introduction to Framework Programming Guide.
To use GLUT on 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
You also need to link your project to the OpenGL and GLUT frameworks. If you are using Xcode 4 to build your project, add the OpenGL and GLUT frameworks by following these steps:
Select the target
Click on the "Build Phases" tab
Under "Link Binary With Libraries", click on the + sign
GLUT.frameworkand click "Add"
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 sample shows the use of standard callbacks and camera control. It is a good starter example to base your own projects on.
Cocoa-based NSOpenGL is recommended over GLUT for window creation on OS X. When you are ready to move from GLUT to NSOpenGL, please see the Cocoa OpenGL sample. This sample demonstrates how to setup windows for drawing and how to handle user events using NSOpenGL.
Document Revision History
Update for Xcode 4.
New document that states the required steps to add GLUT and OpenGL to an Xcode project.