3

I'm currently in the progress to port my iPhone game to the iPhone 5 resolution. I included the Default-568h@2x.png and

[[UIscreen mainScreen] bounds].size;

gives me the iPhone 5 resolution (320x568px). But the renderBuffer I create in OpenglES 1.1 gets only the old iPhone resolution (640x960px). The way I create the render buffer looks like this:

glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

GLint frameBufferWidth, frameBufferHeight;
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &frameBufferWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &frameBufferHeight);

When I'm running the game on the iPhone 5 the game only covers the first 960 pixels of the screen and is squeezed.

Does anybody have an idea how I can create a render buffer that fits the size of the iPhone 5 screen?

Prakash K
  • 11,669
  • 6
  • 51
  • 109

2 Answers2

2

I found the solution. It wasn't a opengl problem. The size option in interface builder of the main window of my application wasn't set after upgrading Xcode to v4.5. Setting the option to "Retina 3.5 full screen" fixed the problem (By doing so the main view is scaled automatically to the 3.5 or 4 inch of the iPhone screen).

This post helped me: How to make a uitableview in interface builder compatible with a 4 inch iPhone

Community
  • 1
  • 1
  • Did you set the Size option in the Simulated Metrics section? Because that would seem to only effect the size displayed in interface builder and not what is actually run on the device. – Andrew Garrison Sep 27 '12 at 13:05
  • Can I ask you to show me a screenshot of your properties for the MainWindow and EAGLView, I can't get this to work properly. Thanks. – Marc Nov 02 '12 at 15:19
0

Actually, if you want to get universal solution, you should change CAEAGLLayer class parameters. In my one old project I also get same problem. But if you change resolution in XIB file for iPhone 5, iPhone 4 will stretch image.

- (id) initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
    CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

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

So, here we need to change resolution:

    if ([[UIScreen mainScreen] bounds].size.height == 568) {
        eaglLayer.bounds = CGRectMake(eaglLayer.bounds.origin.x, eaglLayer.bounds.origin.y, 320, 568);
        eaglLayer.position = CGPointMake(160, 284);
    }

And after that this code

GLint frameBufferWidth, frameBufferHeight;
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &frameBufferWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &frameBufferHeight);

get right Height.

mefik
  • 346
  • 3
  • 5