So you want to get started coding OpenGL on the mac, but what API should you use?
Apple seems to hint pretty heavily towards Objective-C with Cocoa + NSOpenGLView, but what if all you really want is an OpenGL display to draw to and not much else? All the XCode project stuff and Cocoa framework can be a real pain in the ass. Surely there is something lower level?
It turns out there is – next you have AGL + Carbon. Carbon is a lower level C API, and AGL seems pretty straightforward (especially if you are used to WGL).
How about fullscreen? Well in this case, the best choice is CGL, the lowest OpenGL API on MacOSX, above which NSOpenGLView and AGL are both built. This is a really cool API, you can capture the entire screen so you get the full performance of the graphics card without other apps slowing you down when they render their UIs. This is a *big* performance gain if you have a shitty integrated graphics chip like I do on my Macbook Air
All of this is not really that hard to do, but the information on how to do all this is pretty spread out.
For example, how do you take a console program and make a .app file without using XCode? How do you create a carbon window? How to process events? How to make the application menu work properly (you have to do this manually…)
All of these things add up to a huge pain in the ass if you just want to get your OpenGL display ASAP, many folks just ended up using Cocoa for this exact reason, but no more!
Here is a little code snippet, it’s my OpenGL Display module I use at home.
It’s got three simple functions:
You can choose between AGL windowed output and CGL fullscreen by flipping a #define, plus it handles window creation, basic window events, quit event handling and simple keyboard input for you.
Take a look at the source code for the display here:
And download the full OpenGL example here:
(to run it just go “make opengl”)
Once you have it up and running, here are some useful references so you can extend its functionality:
OpenGL Programming Guide for MacOSX
Quartz Display Services
Window Manager Reference
Carbon Event Manager