Rendering the colour buffer to a texture was relatively easy, but for some reason I can't seem to render to a depth texture. If I follow the example provided in the spec, I get a "framebuffer incomplete" error.
I'm using a Radeon 9700 Pro with the Cat 5.7 drivers. Here's the relevant functions:
I'm using a Radeon 9700 Pro with the Cat 5.7 drivers. Here's the relevant functions:
Code:
void CreateRenderTarget ()
{
glGenFramebuffersEXT (1, &g_nFrameBuffer);
glGenRenderbuffersEXT (1, &g_nDepthBuffer);
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, g_nDepthBuffer);
glRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 512, 512);
CheckFrameBufferStatus ();
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, 0);
}
void LoadDepthTarget ()
{
while (glGetError () != GL_NO_ERROR);
glGenTextures (1, &g_nDepthTarget);
glBindTexture (GL_TEXTURE_2D, g_nDepthTarget);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 512, 512, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
CheckGLErrors ();
glBindTexture (GL_TEXTURE_2D, 0);
}
void Draw ()
{
glMatrixMode (GL_MODELVIEW);
// draw to the texture
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, g_nFrameBuffer);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, g_nDepthTarget, 0);
CheckFrameBufferStatus ();
glClearColor (0.5f, 0.0f, 0.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (0.0f, 0.0f, -100.0f);
DrawBackground ();
glPopMatrix ();
// draw to the back buffer
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glTranslatef (0.0f, 0.0f, -100.0f);
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, g_nDepthTarget);
DrawBackground ();
glPopMatrix ();
glDisable (GL_TEXTURE_2D);
SDL_GL_SwapBuffers ();
}