You’ll be using the OpenGL ES API to render the arrow, but OpenGL is only one of many graphics technologies supported on the iPhone. At first, it can be confusing which of these technologies is most appropriate for your requirements. It’s also not always obvious which technologies are iPhone-specific and which cross over into general Mac OS X development.
Apple neatly organizes all of the iPhone’s public APIs into four layers: Cocoa Touch, Media Services, Core Services, and Core OS. Mac OS X is a bit more sprawling, but it too can be roughly organized into four layers, as shown in Figure 1-1.
Despite the similarities between the two
platforms, they diverge quite a bit in their handling of OpenGL. Figure 1-1 includes some OpenGL-related classes, shown in
NSOpenGLView class in Mac OS X does not exist
on the iPhone, and the iPhone’s
CAEGLLayer classes are absent on Mac OS X. The OpenGL API
itself is also quite different in the two platforms, because Mac OS X
supports full-blown OpenGL while the iPhone relies on the more svelte OpenGL
Vector-based graphics library that supports alpha blending, layers, and anti-aliasing. This is also available on Mac OS X. Applications that leverage Quartz technology must reference a framework (Apple’s term for a bundle of resources and libraries) known as Quartz Core.
This book chiefly deals with OpenGL ES, the only technology in the previous list that isn’t Apple-specific. The OpenGL ES specification is controlled by a consortium of companies called the Khronos Group. Different implementations of OpenGL ES all support the same core API, making it easy to write portable code. Vendors can pick and choose from a formally defined set of extensions to the API, and the iPhone supports a rich set of these extensions. We’ll cover many of these extensions throughout this book.
Yes, you do need a Mac to develop applications for the iPhone App Store! Developers with a PC background should quell their fear; my own experience was that the PC-to-Apple transition was quite painless, aside from some initial frustration with a different keyboard.
Xcode serves as Apple’s preferred development
environment for Mac OS X. If you are new to Xcode, it might initially
strike you as resembling an email client more than an IDE. This layout is
actually quite intuitive; after learning the keyboard shortcuts, I found
Xcode to be a productive environment. It’s also fun to work with. For
example, after typing in a closing delimiter such as
( momentarily glows and seems to push
itself out from the screen. This effect is pleasant and subtle; the only
thing missing is a kitten-purr sound effect. Maybe Apple will add that to
the next version of Xcode.
Now we come to the elephant in the room. At some point, you’ve probably heard that Objective-C is a requirement for iPhone development. You can actually use pure C or C++ for much of your application logic, if it does not make extensive use of UIKit. This is especially true for OpenGL development because it is a C API. Most of this book uses C++; Objective-C is used only for the bridge code between the iPhone operating system and OpenGL ES.
The origin of Apple’s usage of Objective-C
lies with NeXT, which was another Steve Jobs company whose technology
was ahead of its time in many ways—perhaps too far ahead. NeXT failed to
survive on its own, and Apple purchased it in 1997. To this day, you can
still find the
NS prefix in many of Apple’s APIs,
including those for the iPhone.
Some would say that Objective-C is not as complex or feature-rich as C++, which isn’t necessarily a bad thing. In many cases, Objective-C is the right tool for the right job. It’s a fairly simple superset of C, making it quite easy to learn.
However, for 3D graphics, I find that certain C++ features are indispensable. Operator overloading makes it possible to perform vector math in a syntactically natural way. Templates allow the reuse of vector and matrix types using a variety of underlying numerical representations. Most importantly, C++ is widely used on many platforms, and in many ways, it’s the lingua franca of game developers.