Search code examples
iphoneopengl-esretina-displaycaeagllayer

iPhone 5 CAEAGLLayer returning wrong bounds


For some reason, my OpenGL app is getting the wrong bounds information for CAEAGLLayer when running in the ios6 4-Inch Retina simulator.

The CAEAGLLayer bounds are printed out as

layer bounds are: (0.000000,0.000000), (320.000000,480.000000)

from this code:

- (id)initWithCoder:(NSCoder*)coder {


    if ((self = [super initWithCoder:coder])) {
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

        eaglLayer.opaque = YES;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];

        printf("layer bounds are: (%f,%f), (%f,%f)\n", eaglLayer.bounds.origin.x, eaglLayer.bounds.origin.y, eaglLayer.bounds.size.width, eaglLayer.bounds.size.height );

        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

        if (!context || ![EAGLContext setCurrentContext:context]) {
            [self release];
            return nil;
        }

        animationInterval = 1.0 / 60.0;
    }
    return self;
}

The window contents are then shifted up, and 0,0 is no longer at the right location.

Anyone have any ideas why the CAEAGLLayer is being set to the incorrect width/height?

Thanks


Solution

  • Ah, someone else had this problem as well. Couldn't find it when I searched before.

    This is the solution:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        self.window.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);
    
    }
    

    From here: How to make a uitableview in interface builder compatible with a 4 inch iPhone