Nothing from OpenGL

Posts: 1
Joined: 2009.03
Post: #1
Hi guys, this is my first post on the forum. I started iPhone development last week, trying to port a game I've been working on from the PC.

I've run into an issue getting OpenGL to display... well... anything.

I'm at a total loss as to what's wrong, so I'd really appreciate any help you can give me. I'm simply at this point after seeing some colour through glClear.

My code to setup OGL, and render, is below;

//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 release];
            return nil;
        else {
            glGenFramebuffersOES(1, &viewFramebuffer);
            glGenRenderbuffersOES(1, &viewRenderbuffer);
            glGenRenderbuffersOES(1, &depthRenderbuffer);
            glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
            [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];
            glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
            glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
            glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
            glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
            glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
            glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
            glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
            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));

                glViewport(0, 0, m_nBackWidth, m_nBackHeight);

            Flow::System::Graphics_iPhoneCore::Instance()->Initialise(self, context, viewFramebuffer, viewRenderbuffer, depthRenderbuffer, backingWidth, backingHeight);
    return self;

And render:
        void Graphics_iPhoneCore::Render()
            // Make sure that you are drawing to the current context
            [EAGLContext setCurrentContext:m_Context];

            glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_uViewBuffer);

            glClearColor(0.0f, 1.0f, 0.0f, 1.0f);


            glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_uRenderBuffer);

            [m_View Present];

- (void)Present
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

There's nothing in the debug console that indicates a problem. I have placed breakpoints and stepped through to ensure that the code is actually being executed. I also littered the code with glGetError messages after every OGL call, and all come back with GL_NO_ERROR.

I'm totally at a loss as to what this could be. Perhaps some setting with the view in the Interface builder? I'm quite new to all this stuff and it's very possible I've missed a setting or checkbox somewhere.

Any help gratefully received. Thanks, Alistair!
Quote this message in a reply
Post Reply