|
|
|
//
|
|
|
|
// ViewController.m
|
|
|
|
// temp
|
|
|
|
//
|
|
|
|
// Created by Joshua Moerman on 07/03/14.
|
|
|
|
// Copyright (c) 2014 Joshua Moerman. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "ViewController.h"
|
|
|
|
#import "Game.h"
|
|
|
|
|
|
|
|
@interface ViewController () {
|
|
|
|
Game * game;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property (nonatomic) EAGLContext *context;
|
|
|
|
- (void)setupGL;
|
|
|
|
- (void)tearDownGL;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad{
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
// all devices supporting ios 5 also support ES 2.0
|
|
|
|
// only a couple of devices support ES 3.0
|
|
|
|
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
|
|
|
assert(self.context);
|
|
|
|
|
|
|
|
GLKView *view = (GLKView *)self.view;
|
|
|
|
view.context = self.context;
|
|
|
|
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
|
|
|
|
view.drawableMultisample = GLKViewDrawableMultisampleNone;
|
|
|
|
view.contentScaleFactor = 1.0;
|
|
|
|
|
|
|
|
self.preferredFramesPerSecond = 60;
|
|
|
|
|
|
|
|
[self setupGL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc{
|
|
|
|
[self tearDownGL];
|
|
|
|
|
|
|
|
if ([EAGLContext currentContext] == self.context) {
|
|
|
|
[EAGLContext setCurrentContext:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning{
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
|
|
|
if (self.isViewLoaded && (!self.view.window)) {
|
|
|
|
self.view = nil;
|
|
|
|
|
|
|
|
[self tearDownGL];
|
|
|
|
|
|
|
|
if ([EAGLContext currentContext] == self.context) {
|
|
|
|
[EAGLContext setCurrentContext:nil];
|
|
|
|
}
|
|
|
|
self.context = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupGL{
|
|
|
|
[EAGLContext setCurrentContext:self.context];
|
|
|
|
game = [[Game alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tearDownGL{
|
|
|
|
[EAGLContext setCurrentContext:self.context];
|
|
|
|
game = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - GLKView and GLKViewController delegate methods
|
|
|
|
|
|
|
|
- (void)update{
|
|
|
|
[game update:(float)self.timeSinceLastUpdate];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect{
|
|
|
|
// If we drew on a different fbo in the meantime, do this
|
|
|
|
[((GLKView *) self.view) bindDrawable];
|
|
|
|
|
|
|
|
[game draw];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|