I am trying to render to two RGB textures, Texture A and Texture B, using an FBO. I then want to take texture A and display it on the left half of a rectangular quad and display Texture B on the right half of the quad.
I initialize my FBO:
glGenFramebuffersEXT( 1, &g_FrameBuffer );
glGenRenderbuffersEXT( 1, &g_DepthRenderBuffer );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, g_DepthRenderBuffer );
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, RENDERBUFFER_WIDTH, RENDERBUFFER_HEIGHT );
glGenTextures( 1, &g_ColorTextureA );
glBindTexture( GL_TEXTURE_2D, g_ColorTextureA );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, RENDERBUFFER_WIDTH, RENDERBUFFER_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glGenTextures( 1, &g_ColorTextureB );
glBindTexture( GL_TEXTURE_2D, g_ColorTextureB );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, RENDERBUFFER_WIDTH, RENDERBUFFER_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
I render the scene to the FBO:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, g_FrameBuffer);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_ColorTextureA, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, g_ColorTextureB, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, g_DepthRenderBuffer);
GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
glDrawBuffers(2, drawBuffers);
glUseProgram(g_GenericShaderProgram);
RenderScene();
glUseProgram(0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, g_ColorTextureA);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, g_ColorTextureB);
My frag shader is simple:
void main( void )
{
gl_FragData[1] = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragData[0] = vec4(0.0, 0.0, 1.0, 1.0);
}
I use imdebug to view the textures after I render to the scene, and they appear just as I would expect, which is one is a blue torus, and one is a red torus. But when I texture the quad with them, I only see the blue torus. I know I must be missing something really simple… What is it?
This is my code that textures the quad
// viewport for 1:1 pixel=texture mapping
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, g_nWindowWidth, 0.0, g_nWindowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport( 0, 0, g_nWindowWidth, g_nWindowHeight );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Render Texture A On Left Half of Quad
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, g_ColorTextureB);
imdebugTexImage(GL_TEXTURE_2D, g_ColorTextureB);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex2f((g_nWindowWidth/2.0), 0.0);
glTexCoord2f(1.0, 1.0);
glVertex2f((g_nWindowWidth/2.0), g_nWindowHeight);
glTexCoord2f(0.0, 1.0);
glVertex2f(0.0, g_nWindowHeight);
glEnd();
// Render Texture B On Right Half of Quad
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, g_ColorTextureB);
imdebugTexImage(GL_TEXTURE_2D, g_ColorTextureB);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2f((g_nWindowWidth/2.0), 0.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(g_nWindowWidth, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(g_nWindowWidth, g_nWindowHeight);
glTexCoord2f(0.0, 1.0);
glVertex2f((g_nWindowWidth/2.0), g_nWindowHeight);
glEnd();