istereo2
diff 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 diff
1.1 --- a/src/ios/viewctl.m Fri Sep 18 23:02:50 2015 +0300 1.2 +++ b/src/ios/viewctl.m Sat Sep 19 05:51:51 2015 +0300 1.3 @@ -1,5 +1,7 @@ 1.4 +#include <stdlib.h> 1.5 +#import <OpenGLES/ES2/glext.h> 1.6 #import "viewctl.h" 1.7 -#import <OpenGLES/ES2/glext.h> 1.8 +#include "istereo.h" 1.9 1.10 @interface ViewController () { 1.11 EAGLContext *ctx; 1.12 @@ -10,6 +12,8 @@ 1.13 1.14 1.15 - (void)create_ad; 1.16 +- (void)show_ad; 1.17 +- (void)hide_ad; 1.18 1.19 - (void)init_gl; 1.20 - (void)destroy_gl; 1.21 @@ -32,7 +36,6 @@ 1.22 1.23 [self create_ad]; 1.24 1.25 - 1.26 [self init_gl]; 1.27 } 1.28 1.29 @@ -70,35 +73,15 @@ 1.30 1.31 - (void)create_ad 1.32 { 1.33 - ad_visible = NO; 1.34 ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner]; 1.35 [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth]; 1.36 - ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); 1.37 + ad_visible = YES; 1.38 + [self hide_ad]; 1.39 [self.view addSubview: ad]; 1.40 ad.delegate = self; 1.41 } 1.42 1.43 -- (void)init_gl 1.44 -{ 1.45 - [EAGLContext setCurrentContext: self->ctx]; 1.46 - 1.47 - glClearColor(1.0, 0.0, 0.0, 1.0); 1.48 -} 1.49 - 1.50 -- (void)destroy_gl 1.51 -{ 1.52 - [EAGLContext setCurrentContext: self->ctx]; 1.53 -} 1.54 - 1.55 - 1.56 -- (void)glkView: (GLKView*)view drawInRect: (CGRect)rect 1.57 -{ 1.58 - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.59 -} 1.60 - 1.61 -// ADBannerDelegate functions 1.62 - 1.63 -- (void)bannerViewDidLoadAd: (ADBannerView*)banner 1.64 +- (void)show_ad 1.65 { 1.66 if(!ad_visible) { 1.67 CGRect rect = ad.frame; 1.68 @@ -108,12 +91,52 @@ 1.69 } 1.70 } 1.71 1.72 +- (void)hide_ad 1.73 +{ 1.74 + if(ad_visible) { 1.75 + ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); 1.76 + ad_visible = NO; 1.77 + } 1.78 +} 1.79 + 1.80 +- (void)init_gl 1.81 +{ 1.82 + [EAGLContext setCurrentContext: self->ctx]; 1.83 + 1.84 + if(init() == -1) { 1.85 + NSLog(@"app initialization failed"); 1.86 + exit(0); 1.87 + } 1.88 +} 1.89 + 1.90 +- (void)destroy_gl 1.91 +{ 1.92 + cleanup(); 1.93 + [EAGLContext setCurrentContext: self->ctx]; 1.94 +} 1.95 + 1.96 + 1.97 +- (void)glkView: (GLKView*)view drawInRect: (CGRect)rect 1.98 +{ 1.99 + redraw(); 1.100 +} 1.101 + 1.102 +- (void)viewDidLayoutSubviews 1.103 +{ 1.104 + CGRect rect = self.view.frame; 1.105 + reshape(rect.size.width, rect.size.height); 1.106 +} 1.107 + 1.108 +// ADBannerDelegate functions 1.109 + 1.110 +- (void)bannerViewDidLoadAd: (ADBannerView*)banner 1.111 +{ 1.112 + [self show_ad]; 1.113 +} 1.114 + 1.115 - (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error 1.116 { 1.117 - if(ad_visible) { 1.118 - ad_visible = NO; 1.119 - ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); 1.120 - } 1.121 + [self hide_ad]; 1.122 1.123 NSLog(@"Failed to retrieve ad"); 1.124 }