istereo2
annotate src/ios/viewctl.m @ 1:2d5abf441307
ads done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Sep 2015 23:02:50 +0300 |
parents | 7841e9365065 |
children | 81d35769f546 |
rev | line source |
---|---|
nuclear@0 | 1 #import "viewctl.h" |
nuclear@0 | 2 #import <OpenGLES/ES2/glext.h> |
nuclear@0 | 3 |
nuclear@0 | 4 @interface ViewController () { |
nuclear@0 | 5 EAGLContext *ctx; |
nuclear@1 | 6 |
nuclear@1 | 7 ADBannerView *ad; |
nuclear@1 | 8 BOOL ad_visible; |
nuclear@0 | 9 } |
nuclear@0 | 10 |
nuclear@1 | 11 |
nuclear@1 | 12 - (void)create_ad; |
nuclear@1 | 13 |
nuclear@1 | 14 - (void)init_gl; |
nuclear@1 | 15 - (void)destroy_gl; |
nuclear@0 | 16 @end |
nuclear@0 | 17 |
nuclear@0 | 18 @implementation ViewController |
nuclear@0 | 19 |
nuclear@0 | 20 - (void)viewDidLoad |
nuclear@0 | 21 { |
nuclear@0 | 22 [super viewDidLoad]; |
nuclear@0 | 23 |
nuclear@0 | 24 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2]; |
nuclear@0 | 25 if(!self->ctx) { |
nuclear@0 | 26 NSLog(@"Failed to create OpenGL ES 2.0 context"); |
nuclear@0 | 27 } |
nuclear@0 | 28 |
nuclear@0 | 29 GLKView *view = (GLKView*)self.view; |
nuclear@0 | 30 view.context = self->ctx; |
nuclear@0 | 31 view.drawableDepthFormat = GLKViewDrawableDepthFormat24; |
nuclear@0 | 32 |
nuclear@1 | 33 [self create_ad]; |
nuclear@1 | 34 |
nuclear@1 | 35 |
nuclear@1 | 36 [self init_gl]; |
nuclear@0 | 37 } |
nuclear@0 | 38 |
nuclear@0 | 39 - (void)dealloc |
nuclear@0 | 40 { |
nuclear@1 | 41 [self destroy_gl]; |
nuclear@0 | 42 |
nuclear@0 | 43 if([EAGLContext currentContext] == self->ctx) { |
nuclear@0 | 44 [EAGLContext setCurrentContext: nil]; |
nuclear@0 | 45 } |
nuclear@0 | 46 } |
nuclear@0 | 47 |
nuclear@0 | 48 - (void)didReceiveMemoryWarning |
nuclear@0 | 49 { |
nuclear@0 | 50 [super didReceiveMemoryWarning]; |
nuclear@0 | 51 |
nuclear@0 | 52 if([self isViewLoaded] && ([[self view] window] == nil)) { |
nuclear@0 | 53 self.view = nil; |
nuclear@0 | 54 |
nuclear@1 | 55 [self destroy_gl]; |
nuclear@0 | 56 |
nuclear@0 | 57 if([EAGLContext currentContext] == self->ctx) { |
nuclear@0 | 58 [EAGLContext setCurrentContext: nil]; |
nuclear@0 | 59 } |
nuclear@0 | 60 self->ctx = nil; |
nuclear@0 | 61 } |
nuclear@0 | 62 |
nuclear@0 | 63 // Dispose of any resources that can be recreated. |
nuclear@0 | 64 } |
nuclear@0 | 65 |
nuclear@0 | 66 - (BOOL)prefersStatusBarHidden |
nuclear@0 | 67 { |
nuclear@0 | 68 return YES; |
nuclear@0 | 69 } |
nuclear@0 | 70 |
nuclear@1 | 71 - (void)create_ad |
nuclear@1 | 72 { |
nuclear@1 | 73 ad_visible = NO; |
nuclear@1 | 74 ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner]; |
nuclear@1 | 75 [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth]; |
nuclear@1 | 76 ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); |
nuclear@1 | 77 [self.view addSubview: ad]; |
nuclear@1 | 78 ad.delegate = self; |
nuclear@1 | 79 } |
nuclear@1 | 80 |
nuclear@1 | 81 - (void)init_gl |
nuclear@0 | 82 { |
nuclear@0 | 83 [EAGLContext setCurrentContext: self->ctx]; |
nuclear@0 | 84 |
nuclear@0 | 85 glClearColor(1.0, 0.0, 0.0, 1.0); |
nuclear@0 | 86 } |
nuclear@0 | 87 |
nuclear@1 | 88 - (void)destroy_gl |
nuclear@0 | 89 { |
nuclear@0 | 90 [EAGLContext setCurrentContext: self->ctx]; |
nuclear@0 | 91 } |
nuclear@0 | 92 |
nuclear@0 | 93 |
nuclear@0 | 94 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect |
nuclear@0 | 95 { |
nuclear@0 | 96 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
nuclear@0 | 97 } |
nuclear@0 | 98 |
nuclear@1 | 99 // ADBannerDelegate functions |
nuclear@1 | 100 |
nuclear@1 | 101 - (void)bannerViewDidLoadAd: (ADBannerView*)banner |
nuclear@1 | 102 { |
nuclear@1 | 103 if(!ad_visible) { |
nuclear@1 | 104 CGRect rect = ad.frame; |
nuclear@1 | 105 rect.origin.y = 0; |
nuclear@1 | 106 ad.frame = rect; |
nuclear@1 | 107 ad_visible = YES; |
nuclear@1 | 108 } |
nuclear@1 | 109 } |
nuclear@1 | 110 |
nuclear@1 | 111 - (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error |
nuclear@1 | 112 { |
nuclear@1 | 113 if(ad_visible) { |
nuclear@1 | 114 ad_visible = NO; |
nuclear@1 | 115 ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); |
nuclear@1 | 116 } |
nuclear@1 | 117 |
nuclear@1 | 118 NSLog(@"Failed to retrieve ad"); |
nuclear@1 | 119 } |
nuclear@1 | 120 |
nuclear@1 | 121 |
nuclear@0 | 122 @end /* implementation ViewController */ |