Blog Hero Image

iPhone Power Unleashed - Part 1: Graphics

Sep 21, 2009
Shawn Simon

Introducing Hugo Munoz as my guest blogger. Hugo is a Senior Engineer with Oshyn and a software expert in OOD with .Net and Java. Hugo also has deep experience with iPhone development, Graphical Modeling and Game Design.

During the past weeks I spent some time playing with my iPhone, I was committed to do a real and extensive proof-of-concept involving two aspects: graphics and designing a suitable n-tier distributed architecture that could be fast enough for hosting a real-time multiplayer game as well as serving as the backend for web 2.0 mobile applications.

In the first part of my journey I did animated 3d character that performs some animations, mainly gestures, in order to build a networked “Simon Says” like application with a pretty simple logic but enough to test the iPhone capabilities in terms of 3d graphics pipeline. I took the 3d model from a previous game I developed, to start it all I did was to use Apple’s default OpenGL ES template and delete the code for the “Spinning Cube”, by doing that you have a perfect sandbox for any experiment.

Before continuing you may be thinking, 3d stuff, where do I start? Well I've been an enthusiast gamer since the age of 5 as I remember (no, I am not kidding). Today I'm 27 so I have a pretty big gaming experience. For more than a decade now I've been programming and designing not only games, based on the premise of “visually appealing software” I’m committed to create jaw dropping applications that aren’t just “eye candy” but also entirely functional software. Taking those facts into account my first advice is not using a 3d engine unless you are in command of the basic skills, I mean you need a good math understanding in terms of Linear Algebra and Geometry, also a strong C/C++ language foundation and off course have some experience with a major graphics API, if you meet those requirements you can go ahead and save some time using a 3d engine, otherwise will be like having a Ferrari and don’t know how to drive.

When writing graphics applications on Unix-based systems such as the iPhone you should use OpenGLES which is the lightweight version of OpenGL, a powerful library of real-time 3D rendering; many modern mobile devices support the older 1.1 version, but 2.0 comes with more shading operations and complex math structures used as the foundation for physics engines, this means that applications written to conform the 2.0 specification will look far better and efficient; so, the first question you must answer is whether your application will support OpenGL ES 1.1, OpenGL ES 2.0, or both... Your application should target OpenGL ES 1.1 if you want to support all iPhones and iPod touches. OpenGL ES 1.1 and 2.0 are incompatible with each other; applications need to be written to support both if they're going to be compatible. A 2.0-only application can’t run on a 1.1-only device.

Here's where it gets interesting, I believe that by now most of the existing iPhone users have upgraded their hardware to 3G or 3GS versions which are OpenGL 2.0 compliant, so I picked the 2.0 specification and the experience was quite pleasant, I coded the 90% of the stuff using pure C code and I had no major problems to include it on my sandbox just had a couple of far pointer exceptions and some macros that I had re-code for Mac (could be interesting to discuss building cross platform software using native C code), well that demonstrates how powerful can be Objective-C, obviously my code at this point is fairly un-optimized, but I was just having fun, in the future I will revamp and comment it for posting.

Latest insights