The GLUT API for OpenGL Configuration
GLUT is an older, tried-and-true, cross-platform API for quick and dirty access to OpenGL application infrastructure. GLUT provides a very simple and straightforward CAPI to create windows, manage device input, monitor windowing events, handle a run loop, and so on. It also provides low-level primitive construction elements such as Spheres, Cubes, and Torii. This API is not unique to the Mac: in fact, you'll find it on most every platform. GLUT allows you to quickly prototype some OpenGL code in such a way that you can test it on every platform on which you must deploy. Although not really a good infrastructure for more complex applications, it's a great way to get started. In this chapter, we'll provide only a cursory examination of the API on the Mac because, with only one or two extremely minor exceptions, GLUT on the Mac is the same as GLUT on any platform.
GLUT first arrived in November 1994, as a creation of Mark Kilgard of SGI. It was created as a basic infrastructure for quickly and simply bringing up a window for OpenGL rendering. Over the years, GLUT evolved into a cross-platform API, providing support through its same basic interface to bring windows up for OpenGL rendering on most Unix systems, including Linux, and eventually adding Windows and Mac support. GLUT evolved in scope, too, as it grew beyond its windowing roots to provide a variety of other wrapper functions. These wrapper functions focus on tasks such as device handling, from keyboard and mouse, to SpaceBall, joysticks, and more. There are also wrapper functions for quick and easy creation of objects such as spheres, cones, and cubes. In addition, font handling, video resize functions, render-to-texture capabilities, and basic dynamic function binding are all features that GLUT has acquired over the years.
Although GLUT has evolved to have a lot of capability, the core of what GLUT is remains unchanged: It is a simple and uniform way of bringing up an OpenGL application in a platform-independent way.
Overview
The GLUT API is part of the overall Apple OpenGL infrastructure. It leverages AppKit for its windowing and event requirements. Figure 9-1 shows where the GLUT API and framework reside relative to other API layers.
Figure 9-1 GLUT API and Framework in the Overall OpenGL Infrastructure on the Mac
The GLUT API lives in your particular SDK framework path or in /System/Library/Frameworks/GLUT.Framework. As with other APIs, linking against GLUT requires specification of this framework path (in our code examples, specifying the variable SDKROOT). Compiling using headers from the GLUT framework will also require specification of the framework. The relevant locations for building and linking with the GLUT framework are found in Table 9-1.
Table 9-1. GLUT Headers, Frameworks, and Overview
Framework path |
/System/Library/Frameworks/GLUT.framework |
Build flag |
-framework GLUT |
Header |
#include<GLUT/glut.h> |
GLUT is an interface for complete, stand-alone applications that provides a comprehensive set of windowing, event management, device input, OpenGL setup, OpenGL configuration, and a few other miscellaneous functions. If for whatever reason you can't find the interface you need within GLUT, you're best off investigating one layer beneath it, such as Cocoa or CGL. For the most part, GLUT provides a rich feature set that can be used to meet all of your full-screen, windowed, and accelerated off-screen needs. With the fundamentals of GLUT described, and armed with the locations in which to fully explore the framework, let's move directly into GLUT configuration.