A sky roads like game with interesting shaders
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

93 lines
2.1 KiB

//
// ViewController.m
// GLGameTemplate
//
// Created by Joshua Moerman on 5/4/12.
// Copyright (c) 2012 Vadovas. All rights reserved.
//
#import "ViewController.h"
#import "App.h"
@interface ViewController () {
App * app;
float width;
float height;
}
@property (strong, nonatomic) EAGLContext *context;
- (void)setupGL;
- (void)tearDownGL;
@end
@implementation ViewController
@synthesize context = _context;
- (void)dealloc {
[_context release];
[super dealloc];
}
#pragma mark - View stuff
- (void)viewDidLoad {
self.preferredFramesPerSecond = 60;
[super viewDidLoad];
self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
if (!self.context) NSLog(@"Failed to create ES context");
GLKView* view = (GLKView* )self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.drawableMultisample = GLKViewDrawableMultisample4X;
[self setupGL];
}
- (void)viewDidUnload {
[super viewDidUnload];
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#pragma mark - openGL setup
- (void)setupGL {
[EAGLContext setCurrentContext:self.context];
app = new App;
}
- (void)tearDownGL {
[EAGLContext setCurrentContext:self.context];
delete app;
app = 0;
}
#pragma mark - GLKView and GLKViewController delegate methods
- (void)update {
if(width != self.view.bounds.size.width || height != self.view.bounds.size.height){
width = self.view.bounds.size.width;
height = self.view.bounds.size.height;
app->resize(width, height);
}
app->update(self.timeSinceLastUpdate);
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
app->draw();
}
@end