istereo2

annotate src/ios/viewctl.m @ 2:81d35769f546

added the tunnel effect source
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Sep 2015 05:51:51 +0300
parents 2d5abf441307
children dc735bdeeb8a
rev   line source
nuclear@2 1 #include <stdlib.h>
nuclear@2 2 #import <OpenGLES/ES2/glext.h>
nuclear@0 3 #import "viewctl.h"
nuclear@2 4 #include "istereo.h"
nuclear@0 5
nuclear@0 6 @interface ViewController () {
nuclear@0 7 EAGLContext *ctx;
nuclear@1 8
nuclear@1 9 ADBannerView *ad;
nuclear@1 10 BOOL ad_visible;
nuclear@0 11 }
nuclear@0 12
nuclear@1 13
nuclear@1 14 - (void)create_ad;
nuclear@2 15 - (void)show_ad;
nuclear@2 16 - (void)hide_ad;
nuclear@1 17
nuclear@1 18 - (void)init_gl;
nuclear@1 19 - (void)destroy_gl;
nuclear@0 20 @end
nuclear@0 21
nuclear@0 22 @implementation ViewController
nuclear@0 23
nuclear@0 24 - (void)viewDidLoad
nuclear@0 25 {
nuclear@0 26 [super viewDidLoad];
nuclear@0 27
nuclear@0 28 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
nuclear@0 29 if(!self->ctx) {
nuclear@0 30 NSLog(@"Failed to create OpenGL ES 2.0 context");
nuclear@0 31 }
nuclear@0 32
nuclear@0 33 GLKView *view = (GLKView*)self.view;
nuclear@0 34 view.context = self->ctx;
nuclear@0 35 view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
nuclear@0 36
nuclear@1 37 [self create_ad];
nuclear@1 38
nuclear@1 39 [self init_gl];
nuclear@0 40 }
nuclear@0 41
nuclear@0 42 - (void)dealloc
nuclear@0 43 {
nuclear@1 44 [self destroy_gl];
nuclear@0 45
nuclear@0 46 if([EAGLContext currentContext] == self->ctx) {
nuclear@0 47 [EAGLContext setCurrentContext: nil];
nuclear@0 48 }
nuclear@0 49 }
nuclear@0 50
nuclear@0 51 - (void)didReceiveMemoryWarning
nuclear@0 52 {
nuclear@0 53 [super didReceiveMemoryWarning];
nuclear@0 54
nuclear@0 55 if([self isViewLoaded] && ([[self view] window] == nil)) {
nuclear@0 56 self.view = nil;
nuclear@0 57
nuclear@1 58 [self destroy_gl];
nuclear@0 59
nuclear@0 60 if([EAGLContext currentContext] == self->ctx) {
nuclear@0 61 [EAGLContext setCurrentContext: nil];
nuclear@0 62 }
nuclear@0 63 self->ctx = nil;
nuclear@0 64 }
nuclear@0 65
nuclear@0 66 // Dispose of any resources that can be recreated.
nuclear@0 67 }
nuclear@0 68
nuclear@0 69 - (BOOL)prefersStatusBarHidden
nuclear@0 70 {
nuclear@0 71 return YES;
nuclear@0 72 }
nuclear@0 73
nuclear@1 74 - (void)create_ad
nuclear@1 75 {
nuclear@1 76 ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner];
nuclear@1 77 [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
nuclear@2 78 ad_visible = YES;
nuclear@2 79 [self hide_ad];
nuclear@1 80 [self.view addSubview: ad];
nuclear@1 81 ad.delegate = self;
nuclear@1 82 }
nuclear@1 83
nuclear@2 84 - (void)show_ad
nuclear@1 85 {
nuclear@1 86 if(!ad_visible) {
nuclear@1 87 CGRect rect = ad.frame;
nuclear@1 88 rect.origin.y = 0;
nuclear@1 89 ad.frame = rect;
nuclear@1 90 ad_visible = YES;
nuclear@1 91 }
nuclear@1 92 }
nuclear@1 93
nuclear@2 94 - (void)hide_ad
nuclear@2 95 {
nuclear@2 96 if(ad_visible) {
nuclear@2 97 ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height);
nuclear@2 98 ad_visible = NO;
nuclear@2 99 }
nuclear@2 100 }
nuclear@2 101
nuclear@2 102 - (void)init_gl
nuclear@2 103 {
nuclear@2 104 [EAGLContext setCurrentContext: self->ctx];
nuclear@2 105
nuclear@2 106 if(init() == -1) {
nuclear@2 107 NSLog(@"app initialization failed");
nuclear@2 108 exit(0);
nuclear@2 109 }
nuclear@2 110 }
nuclear@2 111
nuclear@2 112 - (void)destroy_gl
nuclear@2 113 {
nuclear@2 114 cleanup();
nuclear@2 115 [EAGLContext setCurrentContext: self->ctx];
nuclear@2 116 }
nuclear@2 117
nuclear@2 118
nuclear@2 119 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect
nuclear@2 120 {
nuclear@2 121 redraw();
nuclear@2 122 }
nuclear@2 123
nuclear@2 124 - (void)viewDidLayoutSubviews
nuclear@2 125 {
nuclear@2 126 CGRect rect = self.view.frame;
nuclear@2 127 reshape(rect.size.width, rect.size.height);
nuclear@2 128 }
nuclear@2 129
nuclear@2 130 // ADBannerDelegate functions
nuclear@2 131
nuclear@2 132 - (void)bannerViewDidLoadAd: (ADBannerView*)banner
nuclear@2 133 {
nuclear@2 134 [self show_ad];
nuclear@2 135 }
nuclear@2 136
nuclear@1 137 - (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error
nuclear@1 138 {
nuclear@2 139 [self hide_ad];
nuclear@1 140
nuclear@1 141 NSLog(@"Failed to retrieve ad");
nuclear@1 142 }
nuclear@1 143
nuclear@1 144
nuclear@0 145 @end /* implementation ViewController */