Why can't I render objects to texture properly using FBO?

Posted by Brett on Stack Overflow See other posts from Stack Overflow or by Brett
Published on 2010-03-25T14:16:00Z Indexed on 2010/03/25 17:53 UTC
Read the original article Hit count: 445

Filed under:

Hello,
I'm trying to implement a simple program using 3 FBO's to render a scene to a texture and display a textured quad. I've successfully done this previously using fragment shaders before projecting to the textured quad but can't get it to work without a shader. What could be wrong?
First I set up my textures

glGenTextures(3, renderTextureID);

for (GLint i = 0; i < 3; i++)
{
    glBindTexture(GL_TEXTURE_2D, renderTextureID[i]);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // this may change with window size changes
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, fboWidth, fboHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}

Next some framebuffer state

glGenFramebuffersEXT(3, framebufferID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[0], 0);
GLenum fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT)
{
    fprintf(stderr, "FBO Error!");
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[1]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[1], 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[2]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[2], 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Then I render the scene

glViewport(0, 0, fboWidth, fboHeight);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawModels();

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, renderTextureID[0]);

glEnable(GL_SCISSOR_TEST);
glViewport(windowWidth/2, 0, fboWidth, fboHeight);
glScissor(windowWidth/2, 0, fboWidth, fboHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_QUADS);
    glTexCoord2i(0, 0);
    glVertex2f(-1.0f, -1.0f);
    glTexCoord2i(1, 0);
    glVertex2f(1.0f, -1.0f);
    glTexCoord2i(1, 1);
    glVertex2f(1.0f, 1.0f);
    glTexCoord2i(0, 1);
    glVertex2f(-1.0f, 1.0f);
glEnd();

glDisable(GL_SCISSOR_TEST);
glutSwapBuffers();

The result is a yellow square. Draw models draws yellow wireframe cubes if not using the FBO so the problem is not that. I've read a previous similar post that talks about using glTexParameterf after generating and binding textures but i've done this.
Thanks...

© Stack Overflow or respective owner

Related posts about opengl