istereo2
annotate src/ios/viewctl.m @ 0:7841e9365065
new istereo done right
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 16 Sep 2015 07:10:02 +0300 |
parents | |
children | 2d5abf441307 |
rev | line source |
---|---|
nuclear@0 | 1 #import "viewctl.h" |
nuclear@0 | 2 #import <OpenGLES/ES2/glext.h> |
nuclear@0 | 3 |
nuclear@0 | 4 @interface ViewController () { |
nuclear@0 | 5 EAGLContext *ctx; |
nuclear@0 | 6 } |
nuclear@0 | 7 |
nuclear@0 | 8 - (void)initgl; |
nuclear@0 | 9 - (void)destroygl; |
nuclear@0 | 10 @end |
nuclear@0 | 11 |
nuclear@0 | 12 @implementation ViewController |
nuclear@0 | 13 |
nuclear@0 | 14 - (void)viewDidLoad |
nuclear@0 | 15 { |
nuclear@0 | 16 [super viewDidLoad]; |
nuclear@0 | 17 |
nuclear@0 | 18 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2]; |
nuclear@0 | 19 if(!self->ctx) { |
nuclear@0 | 20 NSLog(@"Failed to create OpenGL ES 2.0 context"); |
nuclear@0 | 21 } |
nuclear@0 | 22 |
nuclear@0 | 23 GLKView *view = (GLKView*)self.view; |
nuclear@0 | 24 view.context = self->ctx; |
nuclear@0 | 25 view.drawableDepthFormat = GLKViewDrawableDepthFormat24; |
nuclear@0 | 26 |
nuclear@0 | 27 [self initgl]; |
nuclear@0 | 28 } |
nuclear@0 | 29 |
nuclear@0 | 30 - (void)dealloc |
nuclear@0 | 31 { |
nuclear@0 | 32 [self destroygl]; |
nuclear@0 | 33 |
nuclear@0 | 34 if([EAGLContext currentContext] == self->ctx) { |
nuclear@0 | 35 [EAGLContext setCurrentContext: nil]; |
nuclear@0 | 36 } |
nuclear@0 | 37 } |
nuclear@0 | 38 |
nuclear@0 | 39 - (void)didReceiveMemoryWarning |
nuclear@0 | 40 { |
nuclear@0 | 41 [super didReceiveMemoryWarning]; |
nuclear@0 | 42 |
nuclear@0 | 43 if([self isViewLoaded] && ([[self view] window] == nil)) { |
nuclear@0 | 44 self.view = nil; |
nuclear@0 | 45 |
nuclear@0 | 46 [self destroygl]; |
nuclear@0 | 47 |
nuclear@0 | 48 if([EAGLContext currentContext] == self->ctx) { |
nuclear@0 | 49 [EAGLContext setCurrentContext: nil]; |
nuclear@0 | 50 } |
nuclear@0 | 51 self->ctx = nil; |
nuclear@0 | 52 } |
nuclear@0 | 53 |
nuclear@0 | 54 // Dispose of any resources that can be recreated. |
nuclear@0 | 55 } |
nuclear@0 | 56 |
nuclear@0 | 57 - (BOOL)prefersStatusBarHidden |
nuclear@0 | 58 { |
nuclear@0 | 59 return YES; |
nuclear@0 | 60 } |
nuclear@0 | 61 |
nuclear@0 | 62 - (void)initgl |
nuclear@0 | 63 { |
nuclear@0 | 64 [EAGLContext setCurrentContext: self->ctx]; |
nuclear@0 | 65 |
nuclear@0 | 66 glClearColor(1.0, 0.0, 0.0, 1.0); |
nuclear@0 | 67 } |
nuclear@0 | 68 |
nuclear@0 | 69 - (void)destroygl |
nuclear@0 | 70 { |
nuclear@0 | 71 [EAGLContext setCurrentContext: self->ctx]; |
nuclear@0 | 72 } |
nuclear@0 | 73 |
nuclear@0 | 74 - (void)update |
nuclear@0 | 75 { |
nuclear@0 | 76 } |
nuclear@0 | 77 |
nuclear@0 | 78 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect |
nuclear@0 | 79 { |
nuclear@0 | 80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
nuclear@0 | 81 } |
nuclear@0 | 82 |
nuclear@0 | 83 @end /* implementation ViewController */ |