istereo2

view 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
line source
1 #import "viewctl.h"
2 #import <OpenGLES/ES2/glext.h>
4 @interface ViewController () {
5 EAGLContext *ctx;
6 }
8 - (void)initgl;
9 - (void)destroygl;
10 @end
12 @implementation ViewController
14 - (void)viewDidLoad
15 {
16 [super viewDidLoad];
18 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
19 if(!self->ctx) {
20 NSLog(@"Failed to create OpenGL ES 2.0 context");
21 }
23 GLKView *view = (GLKView*)self.view;
24 view.context = self->ctx;
25 view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
27 [self initgl];
28 }
30 - (void)dealloc
31 {
32 [self destroygl];
34 if([EAGLContext currentContext] == self->ctx) {
35 [EAGLContext setCurrentContext: nil];
36 }
37 }
39 - (void)didReceiveMemoryWarning
40 {
41 [super didReceiveMemoryWarning];
43 if([self isViewLoaded] && ([[self view] window] == nil)) {
44 self.view = nil;
46 [self destroygl];
48 if([EAGLContext currentContext] == self->ctx) {
49 [EAGLContext setCurrentContext: nil];
50 }
51 self->ctx = nil;
52 }
54 // Dispose of any resources that can be recreated.
55 }
57 - (BOOL)prefersStatusBarHidden
58 {
59 return YES;
60 }
62 - (void)initgl
63 {
64 [EAGLContext setCurrentContext: self->ctx];
66 glClearColor(1.0, 0.0, 0.0, 1.0);
67 }
69 - (void)destroygl
70 {
71 [EAGLContext setCurrentContext: self->ctx];
72 }
74 - (void)update
75 {
76 }
78 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect
79 {
80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
81 }
83 @end /* implementation ViewController */