istereo2

view 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
line source
1 #import "viewctl.h"
2 #import <OpenGLES/ES2/glext.h>
4 @interface ViewController () {
5 EAGLContext *ctx;
7 ADBannerView *ad;
8 BOOL ad_visible;
9 }
12 - (void)create_ad;
14 - (void)init_gl;
15 - (void)destroy_gl;
16 @end
18 @implementation ViewController
20 - (void)viewDidLoad
21 {
22 [super viewDidLoad];
24 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2];
25 if(!self->ctx) {
26 NSLog(@"Failed to create OpenGL ES 2.0 context");
27 }
29 GLKView *view = (GLKView*)self.view;
30 view.context = self->ctx;
31 view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
33 [self create_ad];
36 [self init_gl];
37 }
39 - (void)dealloc
40 {
41 [self destroy_gl];
43 if([EAGLContext currentContext] == self->ctx) {
44 [EAGLContext setCurrentContext: nil];
45 }
46 }
48 - (void)didReceiveMemoryWarning
49 {
50 [super didReceiveMemoryWarning];
52 if([self isViewLoaded] && ([[self view] window] == nil)) {
53 self.view = nil;
55 [self destroy_gl];
57 if([EAGLContext currentContext] == self->ctx) {
58 [EAGLContext setCurrentContext: nil];
59 }
60 self->ctx = nil;
61 }
63 // Dispose of any resources that can be recreated.
64 }
66 - (BOOL)prefersStatusBarHidden
67 {
68 return YES;
69 }
71 - (void)create_ad
72 {
73 ad_visible = NO;
74 ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner];
75 [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
76 ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height);
77 [self.view addSubview: ad];
78 ad.delegate = self;
79 }
81 - (void)init_gl
82 {
83 [EAGLContext setCurrentContext: self->ctx];
85 glClearColor(1.0, 0.0, 0.0, 1.0);
86 }
88 - (void)destroy_gl
89 {
90 [EAGLContext setCurrentContext: self->ctx];
91 }
94 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect
95 {
96 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
97 }
99 // ADBannerDelegate functions
101 - (void)bannerViewDidLoadAd: (ADBannerView*)banner
102 {
103 if(!ad_visible) {
104 CGRect rect = ad.frame;
105 rect.origin.y = 0;
106 ad.frame = rect;
107 ad_visible = YES;
108 }
109 }
111 - (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error
112 {
113 if(ad_visible) {
114 ad_visible = NO;
115 ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height);
116 }
118 NSLog(@"Failed to retrieve ad");
119 }
122 @end /* implementation ViewController */