istereo2

view 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
line source
1 #include <stdlib.h>
2 #import <OpenGLES/ES2/glext.h>
3 #import "viewctl.h"
4 #include "istereo.h"
6 @interface ViewController () {
7 EAGLContext *ctx;
9 ADBannerView *ad;
10 BOOL ad_visible;
11 }
14 - (void)create_ad;
15 - (void)show_ad;
16 - (void)hide_ad;
18 - (void)init_gl;
19 - (void)destroy_gl;
20 @end
22 @implementation ViewController
24 - (void)viewDidLoad
25 {
26 [super viewDidLoad];
28 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
29 if(!self->ctx) {
30 NSLog(@"Failed to create OpenGL ES 2.0 context");
31 }
33 GLKView *view = (GLKView*)self.view;
34 view.context = self->ctx;
35 view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
37 [self create_ad];
39 [self init_gl];
40 }
42 - (void)dealloc
43 {
44 [self destroy_gl];
46 if([EAGLContext currentContext] == self->ctx) {
47 [EAGLContext setCurrentContext: nil];
48 }
49 }
51 - (void)didReceiveMemoryWarning
52 {
53 [super didReceiveMemoryWarning];
55 if([self isViewLoaded] && ([[self view] window] == nil)) {
56 self.view = nil;
58 [self destroy_gl];
60 if([EAGLContext currentContext] == self->ctx) {
61 [EAGLContext setCurrentContext: nil];
62 }
63 self->ctx = nil;
64 }
66 // Dispose of any resources that can be recreated.
67 }
69 - (BOOL)prefersStatusBarHidden
70 {
71 return YES;
72 }
74 - (void)create_ad
75 {
76 ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner];
77 [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
78 ad_visible = YES;
79 [self hide_ad];
80 [self.view addSubview: ad];
81 ad.delegate = self;
82 }
84 - (void)show_ad
85 {
86 if(!ad_visible) {
87 CGRect rect = ad.frame;
88 rect.origin.y = 0;
89 ad.frame = rect;
90 ad_visible = YES;
91 }
92 }
94 - (void)hide_ad
95 {
96 if(ad_visible) {
97 ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height);
98 ad_visible = NO;
99 }
100 }
102 - (void)init_gl
103 {
104 [EAGLContext setCurrentContext: self->ctx];
106 if(init() == -1) {
107 NSLog(@"app initialization failed");
108 exit(0);
109 }
110 }
112 - (void)destroy_gl
113 {
114 cleanup();
115 [EAGLContext setCurrentContext: self->ctx];
116 }
119 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect
120 {
121 redraw();
122 }
124 - (void)viewDidLayoutSubviews
125 {
126 CGRect rect = self.view.frame;
127 reshape(rect.size.width, rect.size.height);
128 }
130 // ADBannerDelegate functions
132 - (void)bannerViewDidLoadAd: (ADBannerView*)banner
133 {
134 [self show_ad];
135 }
137 - (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error
138 {
139 [self hide_ad];
141 NSLog(@"Failed to retrieve ad");
142 }
145 @end /* implementation ViewController */