OpenGL in Cocoa

OpenGL, the Open Graphics Library, is the standard for 3D graphics on a variety of computers, not just on Macs, but on Windows, Linux and UNIX, as well as the iPhone, iPad and other mobile devices. Some time ago I picked up the OpenGL SuperBible because it has a thorough set of tutorials, as well as a chapter at the end discussing how to create applications for OS X, including ways to capture the screen to do full-screen video (only OpenGL showing up for the user to see). Be warned that I have the fourth edition of the book. The fifth edition has come out this year, so these examples won’t match the current one.

Chapter 1 of the OpenGL SuperBible, 4th edition, is introductory material, so I’ll immediately jump into Chapter 2, which contains the first three example programs.

The book’s example programs use GLUT, the GL Utility Toolkit, which provides a platform-independent way of opening windows, dealing with user input, creating timers, and other system tasks. Since this blog’s topic is Cocoa, I plan on translating the C and GLUT-based examples into Objective-C using Cocoa directly. The chapter has three example programs, which I’ll refer to as VerySimpleOpenGL, GLRect and Bouncing Square.

The original version of the chapter’s first program, Simple, is on page 48 of the fourth edition SuperBible. It simply creates a window filled in blue. I got it to run on the first try, although I have to admit that I stole the structure of the program (and many of the necessary OS X specifics) from the OpenGL example in Hillegass’s Cocoa Programming for Mac OS X. The key thing to remember when creating a new OpenGL project in Xcode is to remember to add the OpenGL and GLUT frameworks. The blue is bright to the point of being obnoxious, so my future backgrounds will use (0.0, 0.0, 0.75, 1.0) as the RGBA color, instead of the book’s (0.0, 0.0, 1.0, 1.0).

I’ll write more on OpenGL in the coming weeks. Leave a comment if you’d like to have me post my code.

This entry was posted in OpenGL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s