OpenGL iOS 2d 4英寸显示屏

时间:2014-07-25 12:45:23

标签: ios opengl-es

我正试图在2d OpenGL iOS应用程序中使4英寸显示器正常工作。它适用于3.5英寸显示器和所有IPad显示器,但在4英寸显示器中切掉底部88像素。我尝试过不同版本的Launch Images,根本没有启动图像。我也尝试过MainWindow.xib的不同版本,根本没有.xib。

Xcode 5中的OpenGL示例适用于3d应用程序,但我尝试转换为2d时遇到了很大问题。我正在使用的代码基于较旧的GLSprite示例。

在创建帧缓冲区时似乎表现出来。在下面的backingHeight总是返回480像素,它应该是568.谢谢。

- (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;
}

感谢大家的回复。我承认在设置视图和帧缓冲区时我真的不知道我在做什么。以下是初始视图的设置方式。它指的是一种叫做“nib文件”的东西,我似乎找不到它。这段代码中是否有任何地方我应该放置视图大小逻辑?我还说我试过没有.xib文件,但我错了。我不介意使用GLKit,但我没有找到一个简单的例子来呈现像我想要的2d背景纹理。

//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;
}

1 个答案:

答案 0 :(得分:1)

负责这一行的是[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];。如果高度的返回值始终为480,则视图本身很可能具有480的高度(尝试确认)。

如果是这样,那么我想找到将其设置为此高度的最快方法是覆盖setFrame:方法并添加断点。