Question

When i try to create a FBO with a texture attached to it in OpenGl ES 2.0 like this:

    glGenFramebuffers(1, &framebuffer);
    glGenTextures(1, &textureId);

    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebuffer, 0);

    GLenum status;
    status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    switch(status) {
        case GL_FRAMEBUFFER_COMPLETE:
            NSLog(@"fbo complete");
            break;

        case GL_FRAMEBUFFER_UNSUPPORTED:
            NSLog(@"fbo unsupported");
            break;

        default:
            /* programming error; will fail on all hardware */
            NSLog(@"Framebuffer Error");
            break;
    }

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

and then apply it like this:

    glBindFramebuffer(GL_FRAMEBUFFER, renderTarget.framebufferId);
    glBindTexture(GL_TEXTURE_2D, renderTarget.textureId);

    glViewport(0, 0, renderTarget.width, renderTarget.height);

then render something on it and finally draw the attached texture to the screen. the result is a empty black screen (everything works fine if i render it to the screen directly). I tried several FBO tutorials (the current code is one of them) but with no difference.

Also when i use the OpenGl debugger from xcode i have warnings like: "Slow framebuffer load Issue" on glDrawArrays but i can also see that the texture is not empty (i can see the texture with the right size and the right glClearColor)

would be great if someone had this issue before and knows what im doing wrong here :)

Thanks in advance

Was it helpful?

Solution

ok solved my problem. there were a few smaller problems but the main problem was that i bound the framebuffer and the texture together (see top related question). the other problem was the $!&()#^ (i mean wonderful) opengl coordinate system (bottom left) but that was a quick fix. now everything is working fine expect of very poor performance when drawing the fullscreen quad, but i will open another question for that.

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