Reputation: 1
I'm trying to get a 4 inch display working correctly in a 2d OpenGL iOS app. It works fine with 3.5 inch displays and all IPad displays, but chops off the bottom 88 pixels in 4 inch displays. I've tried different versions of Launch Images and no Launch Image at all. I've also tried different variations of MainWindow.xib and no .xib at all.
The OpenGL example in Xcode 5 works well for 3d apps, but I've had big problems with it trying to convert to 2d. The code I'm using is based on the older GLSprite sample.
It seems to manifest itself when creating the Frame Buffer. In the following backingHeight is always returned as 480 pixels when it should be 568. Thanks.
- (BOOL)createFramebuffer
{
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
return YES;
}
Thanks everybody for responding. I admit I really don't know what I'm doing when setting up the views and frame buffer. The following is how the initial view is set up. It refers to something called a "nib file," which I can't seem to find. Is there any place in this code where I should put the view size logic? I also said I tried to do it without an .xib file, but I was wrong. I don't mind using GLKit, but I haven't found a simple example that renders 2d background textures like I want to do.
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (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:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) {
[self release];
return nil;
}
animating = FALSE;
displayLinkSupported = FALSE;
animationFrameInterval = 1;
displayLink = nil;
animationTimer = nil;
// A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
// class is used as fallback when it isn't available.
NSString *reqSysVer = @"3.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
displayLinkSupported = TRUE;
[self setupView];
[self drawView];
}
return self;
}
Upvotes: 0
Views: 55
Reputation: 16774
The line responsible for this is [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];
. If the returned value for height is always 480 then the view itself is most likely having a height of 480 (try to confirm that).
If so then I guess the quickest approach of finding what setts it to this height is overriding setFrame:
method and adding a breakpoint.
Upvotes: 1