Question

Upgrading to the iOS SDK 4.2 I'm experiencing several misbehaviors in my application (another one is asked here). The one I'm gonna ask your help for concerns an OpenGL view (an EAGLView subclass) that renders no more the 3d model I'm putting in.

The view is allocated and it appears to recognize the gestures but its content is not visible (I've checked that it's about the view and not the misplacing of the model by coloring the background: it does not color it through glClearColor()).

When I double tap it it shall resize (it goes fullscreen, before this it is a little UIVIew) calling this method:

- (void)animateToGrow{
    DNSLog(@"grow");
    grow = YES;
    oldFrame = self.frame;
    oldCenter = self.center;

    [UIView beginAnimations:@"MoveAndStrech" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];

    self.frame = CGRectMake(0, 0, WIDTH, HEIGHT); 
    self.center = CGPointMake(CENTER_X, CENTER_Y);
    [UIView commitAnimations];
    [self setupGLPerspectiveNear:0.1 far:1000];
}

and magically the model appears, and even the background gets colored.

I have a method that resizes it and make it back to its previous frame and center position and when it gets called the view becomes 'empty' again.

Prior to Any suggestion? (I can post more code if needed)

UPDATE This is happening on the simulator (cannot test on a device at the moment). If this is an acknowledged bug, has anyone a reference from Apple docs?

UPDATE 2 I'm using OpenGL ES 1.1 and not 2.0.

Here is what I do in EAGLView's layoutSubViews :

- (void)layoutSubviews 
{
    [EAGLContext setCurrentContext:_context];
    [self destroyFramebuffer];
    [self createFramebuffer];
    [self drawView];
}

And this is my createFramebuffer

- (BOOL)createFramebuffer
{
    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);

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &_backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &_backingHeight);

    if (_useDepthBuffer) 
    {
        glGenRenderbuffersOES(1, &_depthRenderbuffer);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, _depthRenderbuffer);
        glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, _backingWidth, _backingHeight);
        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, _depthRenderbuffer);
    }

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

UPDATE 3

If I create the view giving it the fullscreen frame (320x480) It appears rendered correctly. In some way It is related to the view dimensions

Was it helpful?

Solution

It took me forever to find this out. Not well documented at all, but it's in the apple docs. On os 4.2 and higher, you need the EAGLview size to be a multiple of 32 pixels in both dimensions for it to work.

OTHER TIPS

Is this in the Simulator? If so, then that is a known bug in the iOS 4.2 Simulator. This bug does not impact the devices themselves.

How are you setting up your OpenGL-hosting layer and the view that it backs? When I try the OpenGL ES sample applications that I have here and here, both run just fine on the 4.2 Simulator, as well as the device.

Perhaps you could compare the initialization used in those examples with your own and see if there is something that you might be missing in the setup process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top