Pro OpenGL ES for iOS

(singke) #1

56 CHAPTER 3: Building a 3D World^


Back to the Fun Stuff: A Simpler Demo

When Xcode 4.2 was released (along with the iOS5 SDK), it changed the default project
of the OpenGL wizard. Previously it produced an OpenGL ES 1 app showing a very
simple 2D scene of a flat bouncing square, compared to the two 3D cubes rotating
around a common center in the OpenGL ES 2 environment. The former was an ideal
project to leverage early on because it was far less fussy than the later one, as
described in Chapter 1. So we’ll use the original demo and variants from here on out as
a foundation project of sorts, starting from a known and easily understood codebase as
a launchpad to bigger and better things.
The easiest way is to either fetch the source from the Apress site or take the example
from Chapter 1 and copy the material from Listings 3-1 and 3-2 over the viewcontroller
content in Chapter 1.
Listing 3-1. The header for the Listing 3-2.

#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>

@interface BouncySquareViewController : GLKViewController //1

@end
Listing 3-2. The classic bouncing square demo with iOS5 modifications.

#import "BouncySquareViewController.h"

@interface BouncySquareViewController ()
{

}

@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKBaseEffect *effect;

@end

@implementation BouncySquareViewController

@synthesize context = _context;
@synthesize effect = _effect;


  • (void)viewDidLoad
    {
    [super viewDidLoad];


self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; //2
Free download pdf