Genetic generation of cars in a 2D environment
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.

111 lines
2.7 KiB

11 years ago
//
// ViewController.m
// iOS GLEssentials
11 years ago
//
// 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;
11 years ago
self.preferredFramesPerSecond = 60;
[self setupGL];
game.windowSize = self.view.bounds.size;
11 years ago
}
- (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)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
game.windowSize = self.view.bounds.size;
}
11 years ago
- (void)setupGL{
[EAGLContext setCurrentContext:self.context];
game = [[Game alloc] init];
CGFloat x = 20;
CGFloat y = 20;
for (NSString * a in game.actions) {
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(x, y, 200, 22)];
[myButton setTitle:a forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: myButton];
y += 22;
}
}
- (void) action:(UIButton*) sender{
[game action:[sender titleForState:UIControlStateNormal]];
11 years ago
}
- (void)tearDownGL{
[EAGLContext setCurrentContext:self.context];
game = nil;
}
#pragma mark - GLKView and GLKViewController delegate methods
- (void)update{
[game update:(float)self.timeSinceLastUpdate];
11 years ago
}
- (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