Buld OpenGL/GLUT Applications under Mac OS X

Xcode comes with all what we need to build a Cocoa application with OpenGL and GLUT and GCC. So, first of all, we need to install Xcode.

Writing Code

An GLUT C/C++ program for Mac OS X should include three header files:

#include   // Header File For The OpenGL32 Library
#include // Header File For The GLu32 Library
#include // Header File For The GLut Library

Note that the locations of these header files in Mac OS X differs from where they are in Linux and Windows (e.g., GL/glut.h)

Building Using GCC

The command line using GCC to build a program main.c is as follows:

gcc -framework GLUT -framework OpenGL -framework Cocoa main.c -o learning

It is notable here that MacOSX uses the concept of so called frameworks. Instead of adding include paths and library names yourself, you add a framework to your compiler call. This is a MacOSX specific extension to gcc.

Building Using Xcode IDE

We can also manage our OpenGL/GLUT projects using Xcode IDE. To create a project, select the project type of “Cocoa Application”. To add/edit the code, remove the auto-generated main.m, add a new main.c, and write our code into main.c. To specify the frameworks in IDE, right click the project and choose “Add Exisiting Frameworks” to add OpenGL and GLUT.