I’ve been working through the OpenGL SuperBible, Fourth Edition, and in order to get to shaders and begin working in OpenGL ES on the iOS, I decided to pick up a copy of iPhone 3D Programming, by Philip Rideout, a Denver author, as it turns out. I’m moving on to this book because my goal is iOS development, and this book gets me there more directly than studying OpenGL and iOS separately.
This book jumps right into application development, with HelloArrow, which puts a sort-of Starship Enterprise symbol on screen, keeping it vertical as the device rotates. There are actually two implementations, one in OpenGL ES 1.1, for earlier iOS devices, and the second in OpenGL ES 2.0, the modern version that uses shaders, which are small C-like programs that are compiled to run directly on the graphics hardware instead of the CPU. Shaders replace the fixed-function pipeline originally used in OpenGL. They were introduced in OpenGL 1.4 as an extension, and became part of the OpenGL core in version 2.0.
The book makes extensive use of C++ to do the heavy lifting for rendering and associated computational tasks, with just enough Objective-C to interface the rendering with iOS. You’ll want to be up on C++ to make your way through the book. Knowing something about Design Patterns will be very helpful—having studied Head First Design Patterns let me recognize what was going on in chapter 1.
The payoff for using C++ is portability: it’s easier to use C++ on other mobile devices, since Objective-C is very much an OS X and iOS peculiarity. I’ve gotten fond of Objective-C since I’ve been using it regularly, but this book is reminding me how powerful C++ is, and how much I enjoyed learning and using it.
The first version of the app uses a C++ renderer based on OpenGL ES 1.1. The second version upgrades to OpenGL ES 2.0, with code that checks if 2.0 is available, and dropping back to 1.1 if necessary.
The errors I came across were all fairly trivial, although hard to find. I had mis-capitalized some variable names, turning the correct Modelview into ModelView, and that kept the symbol from displaying: all I got was the gray background.
Here’s the final result: