tags:

views:

135

answers:

2

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);
    ADDED: glEnable(GL_TEXTURE_2D);
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);
    ADDED: glDisable(GL_TEXTURE_2D);
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...

A: 

Compare your code to the examples, perhaps there are discrepancies.

genpfault
A: 

I don't see any clear on the final buffer. If that is indeed the case, and you have Z-testing enabled, then all the drawing on the final render buffer (assuming you use the same Z-buffer) will get Z-rejected.

It's a wild guess though, because there is still a lot of code that is missing. I assume you don't have any GL error ?

Edit to add: Did you enable texturing in the fixed function ? glEnable(GL_TEXTURE_2D);

Bahbar
Theres no GL error. If I use a simple fragment shader using glUseProgram before drawing the textured quad then output is fine although if I try to use the texture after calling glUseProgram(0) I get the yellow square again
Brett
@Brett: Then it's an issue with your fixed function setup. I added another guess to my answer.
Bahbar
Ok. So I think I get it. I added a glEnable(GL_TEXTURE_2D) to the original code above and now it works, thanks Bahbar.
Brett