Search code examples
iphoneios4opengl-esxcode4

Help understanding the Xcode 4 Project Template for OpenGL


In Xcode 4, the OpenGL ES template/boilerplate is different from previous versions. (All of the tutorials I have read and watched use Xcode 3.X) When I start a new project, there is no ES1renderer or ES2renderer. All of the code that is usually found in these classes is found in ViewContoller. My question is: should I create those classes myself, or just place my code in the ViewController? (I'm new to OpenGL ES--and iPhone development for that matter--so be gentle).


Solution

  • The old template neatly divided ES 1.1 code from 2.0 code. That makes sense because the two APIs are very different in significant ways. However, it's rare that a shipping app actually supports both — normally you'll either go 1.1 and limit yourself in some visual respects or 2.0 and limit yourself in hardware support. 2.0 is available from the iPhone 3GS onwards and on all iPads, but not on the lowest capacity last generation iPod Touch (ie, the one that stopped being current in September 2010) so there are some people who've owned for less than a year that you'll be eliminating from your potential customer pool.

    The new template takes that issue out of the (latest) sample EAGLView. You have to hand it a suitable context, and then it does only context neutral things. The ES 1.1 or 2.0 logic is now in the view controller. Lines 43 to 57 ensure a suitable context is created for the latest supported version of GLES, line 187 branches depending on the API in use.

    The CADisplayLink for timing is also now in the view controller.

    So for library, boilerplate code you'd probably want something like the new EAGLView, which makes no assumptions about API or about how you'll push graphics to it. In terms of how you'll draw, you'll probably just want to pick a horse, and implement either ES1 or ES2.