istereo2

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ios/viewctl.m	Wed Sep 16 07:10:02 2015 +0300
     1.3 @@ -0,0 +1,83 @@
     1.4 +#import "viewctl.h"
     1.5 +#import <OpenGLES/ES2/glext.h>
     1.6 +
     1.7 +@interface ViewController () {
     1.8 +	EAGLContext *ctx;
     1.9 +}
    1.10 +
    1.11 +- (void)initgl;
    1.12 +- (void)destroygl;
    1.13 +@end
    1.14 +
    1.15 +@implementation ViewController
    1.16 +
    1.17 +- (void)viewDidLoad
    1.18 +{
    1.19 +    [super viewDidLoad];
    1.20 +
    1.21 +    self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
    1.22 +    if(!self->ctx) {
    1.23 +        NSLog(@"Failed to create OpenGL ES 2.0 context");
    1.24 +    }
    1.25 +
    1.26 +    GLKView *view = (GLKView*)self.view;
    1.27 +    view.context = self->ctx;
    1.28 +    view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
    1.29 +
    1.30 +	[self initgl];
    1.31 +}
    1.32 +
    1.33 +- (void)dealloc
    1.34 +{
    1.35 +	[self destroygl];
    1.36 +
    1.37 +    if([EAGLContext currentContext] == self->ctx) {
    1.38 +        [EAGLContext setCurrentContext: nil];
    1.39 +    }
    1.40 +}
    1.41 +
    1.42 +- (void)didReceiveMemoryWarning
    1.43 +{
    1.44 +    [super didReceiveMemoryWarning];
    1.45 +
    1.46 +    if([self isViewLoaded] && ([[self view] window] == nil)) {
    1.47 +        self.view = nil;
    1.48 +
    1.49 +        [self destroygl];
    1.50 +
    1.51 +        if([EAGLContext currentContext] == self->ctx) {
    1.52 +            [EAGLContext setCurrentContext: nil];
    1.53 +        }
    1.54 +        self->ctx = nil;
    1.55 +    }
    1.56 +
    1.57 +    // Dispose of any resources that can be recreated.
    1.58 +}
    1.59 +
    1.60 +- (BOOL)prefersStatusBarHidden
    1.61 +{
    1.62 +    return YES;
    1.63 +}
    1.64 +
    1.65 +- (void)initgl
    1.66 +{
    1.67 +    [EAGLContext setCurrentContext: self->ctx];
    1.68 +
    1.69 +	glClearColor(1.0, 0.0, 0.0, 1.0);
    1.70 +}
    1.71 +
    1.72 +- (void)destroygl
    1.73 +{
    1.74 +    [EAGLContext setCurrentContext: self->ctx];
    1.75 +}
    1.76 +
    1.77 +- (void)update
    1.78 +{
    1.79 +}
    1.80 +
    1.81 +- (void)glkView: (GLKView*)view drawInRect: (CGRect)rect
    1.82 +{
    1.83 +    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.84 +}
    1.85 +
    1.86 +@end	/* implementation ViewController */