My Start with OpenGL ES for iPhone

by Rob Bajorek
Originally posted: May 6, 2009

This post is about my start at OpenGL programming on the iPhone.

I have an iPhone project that needs animation.  After considering using 2D vs. 3D objects, OpenGL looked like the best option.  Once I made that decision, I needed to start learning OpenGL. And how did that go? Let’s just say learning OpenGL is a non-trivial exercise.

First stop, the Apple Docs

The natural place to start learning OpenGl for iPhone is Apple. The iPhone Developer site has a lot of information about iPhone programming. In particular, the iPhone Application Programming Guide has a section on OpenGL ES. The information starts with setting up a drawing context and view for OpenGL. There are a number of suggestions, lists of supported features, and comparisons between the simulator and the device. But, it doesn’t really talk about programming in OpenGL. In short, it’s a great list of tips, but it assumes you already know what you’re doing. Surely I’ll come back to this page, but it’s not the place to start.

Apple did include some links, though. That’s where I went next.

OpenGL ES, the standard

The iPhone’s OpenGL is not the full spec. It’s a special system designed for embedded devices and consoles called OpenGL ES, specifically version 1.1. The keepers of the standard are the Khronos Group.

The main document that I used from Khronos was the OpenGL ES 1.1.12 Full Specification (PDF). This document describes the specification, although the target audience is the OpenGL ES implementor, not the application programmer. Still, I picked up core concepts like matrix modes and building polygons. I couldn’t actually do anything with that knowledge since it didn’t tell me how to build an app.

At this point, I decided to ask Google.

The Red Book

I looked through some forums and tutorials, and the suggestion I tried next was to learn from the “official” guide to OpenGL, AKA the Red Book. By far, the official guide was the best introduction I found to OpenGL. This guide is an actual introduction, teaching you how to program from scratch.

This reminds me of an important point; OpenGL is a C API, not an Objective-C one. No classes or methods here. It’s globals and functions. There’s not much difference, but it may confuse you a bit if you started with Objective-C.

After digging into this book, I started to understand how OpenGL works and I could actually write code! It didn’t translate one-to-one to the iPhone because this is an OpenGL book, not an OpenGL ES one. However, it wasn’t difficult to apply the book to the iPhone. If I did get stuck, someone else did too and I found an answer from Google.

Also, Apple’s OpenGL ES examples made more sense. I started with those and built on them while going through the Red Book.

The Recommendation

I feel comfortable with OpenGL ES now. In fact, I already have a working 3D app integrated with the Bullet Physics library. My recommendation if you’re starting from scratch is to use the Red Book and the OpenGL examples from Apple. Play with the example projects until you feel comfortable, then go from there.