Pro OpenGL ES for iOS

(singke) #1

CHAPTER 1: Computer Graphics: From Then to Now (^17)
@implementation TwoCubesViewController
@synthesize context = _context;
@synthesize effect = _effect;



  • (void)viewDidLoad
    {
    [super viewDidLoad];


self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; //4


if (!self.context) {
NSLog(@"Failed to create ES context");
}


GLKView view = (GLKView )self.view; //5
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24; //6


[self setupGL];
}



  • (void)viewDidUnload
    {
    [super viewDidUnload];


[self tearDownGL];


if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}



  • (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc. that aren't in use.
    }


  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientatio
    n
    {
    // Return YES for supported orientations.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
    return YES;
    }
    }



Free download pdf