开发者

How to change canvas size in OpenGL? glClearColor is only painting a small box

When I run the following open gl command, it only paints the bottom left part of the ipad screen red.

glClearColor(255.0f, 0.0f, 0.0f, 0.0f);

开发者_运维百科

How to change canvas size in OpenGL? glClearColor is only painting a small box

How do I make it so the whole screen gets painted red?

Thanks!


You probably haven't set the framebuffer to the correct size. If you are on an iPhone 4, the most common mistake is to use the reported view dimensions, which are the same as for the earlier models, even though the iPhone 4 has twice the resolution.

Here's how I do it in my app (Important Caveat: this is all black-magic to me, so take it with a grain of salt, and please don't ask me to explain it):

- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer {
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer];
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &vWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &vHeight);

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderBuffer);
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, vWidth, vHeight);

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


Does glViewport() not work?


I am on an iPad using example code made for the iPhone

Is it possible that the window size in the code is hard coded to the smaller iPhone screen dimensions?

Edit:
This idevgames forum post looks like the same xcode issue (not OpenGL), caused by:

  1. Starting with an iPhone project in xcode
  2. Incorrect settings in the .xib file

Two solutions, neither tested by me are:
1)

UIWindow resizing can be achieved with manual conversion of .xib files to iPad version using Interface Builder. This is mentioned in iOS 4.0 Release Notes in Known Issues->Xcode section.
This do the trick for me.

2)

Save yourself a lot of trouble, just create a new iPad OGLES app in xcode, everything will already be setup and working for you, drag your files in from your old xcode project into your new one, update the xib with the correct app delate and your done. I had to start a whole new project today and do this just to get the MF#!!FS#$*! code signing to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜