istereo2
diff src/ios/viewctl.m @ 3:dc735bdeeb8a
mkicons script
added content-scale support for "retina" devices
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 21 Sep 2015 07:40:34 +0300 |
parents | 81d35769f546 |
children | d4fed8aac9a6 |
line diff
1.1 --- a/src/ios/viewctl.m Sat Sep 19 05:51:51 2015 +0300 1.2 +++ b/src/ios/viewctl.m Mon Sep 21 07:40:34 2015 +0300 1.3 @@ -5,6 +5,7 @@ 1.4 1.5 @interface ViewController () { 1.6 EAGLContext *ctx; 1.7 + float pixel_scale; 1.8 1.9 ADBannerView *ad; 1.10 BOOL ad_visible; 1.11 @@ -25,6 +26,7 @@ 1.12 { 1.13 [super viewDidLoad]; 1.14 1.15 + 1.16 self->ctx = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES2]; 1.17 if(!self->ctx) { 1.18 NSLog(@"Failed to create OpenGL ES 2.0 context"); 1.19 @@ -34,6 +36,14 @@ 1.20 view.context = self->ctx; 1.21 view.drawableDepthFormat = GLKViewDrawableDepthFormat24; 1.22 1.23 + if([view respondsToSelector: NSSelectorFromString(@"contentScaleFactor")]) { 1.24 + pixel_scale = [[UIScreen mainScreen] scale]; 1.25 + view.contentScaleFactor = pixel_scale; 1.26 + printf("pixel scale: %g\n", pixel_scale); 1.27 + } else { 1.28 + pixel_scale = 1.0f; 1.29 + } 1.30 + 1.31 [self create_ad]; 1.32 1.33 [self init_gl]; 1.34 @@ -124,7 +134,10 @@ 1.35 - (void)viewDidLayoutSubviews 1.36 { 1.37 CGRect rect = self.view.frame; 1.38 - reshape(rect.size.width, rect.size.height); 1.39 + int xsz = rect.size.width * pixel_scale; 1.40 + int ysz = rect.size.height * pixel_scale; 1.41 + reshape(xsz, ysz); 1.42 + printf("viewport %dx%d (scale: %g)\n", xsz, ysz, pixel_scale); 1.43 } 1.44 1.45 // ADBannerDelegate functions