FBO render-to-texture without depth test.. why?

Hey…

I’m trying to render my view of a scene to a texture using a FBO. However whenever I enable the FBO the depth test is disabled and it doesn’t seem to work by enabling it. Can anybody help me?

void CreateTextureWithFBO(void)
{ 
  // creates texture
  glGenTextures (1, &texture);
  glBindTexture (texture_target, texture);
  glTexImage2D (texture_target, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP);

  // create fbo and attach texture
  glGenFramebuffersEXT (1, &textureFBO);
  glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, textureFBO);
  glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texture_target, texture, 0);
  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, texture);

  // Enable depth test... (not sure if this has any effect here)
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  
  glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
}

void RenderTexture(void)
{
  glEnable(GL_DEPTH_TEST);    // Trying to enable depth test (no effect)

  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, textureFBO);
  glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    glEnable(GL_DEPTH_TEST);    // Trying to enable depth test (no effect)
    
    pPaintPistolCamera->updatePerspectiveCamera(paintPistolPosition, paintPistolRotation);  // setup camera position
    glViewport(0, 0, textureWidth, textureHeight);  // Viewport

    glEnable(texture_target);
    glBindTexture(texture_target, surfaceTexture);  // surfaceTexture is an ordinary RGBA texture
    glCallList(objectDisplayList);                  // scene
    glBindTexture(texture_target, NULL);            // Deselect texture
    glDisable(texture_target);
  glPopMatrix();
  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);  // Unbind fbo 0
}

I’ve tested the code on two graphic cards:

  • ATI X600 mobility (driver Omega 3.8.205)
  • NVidia 5600FX (forceware 81.98)

and depth test is not enabled on either of the two… Why?

you do not bind any depth buffer

Sounds about right… But how do I do that when?
using glBindRenderbufferEXT?

Never mind… I got it! Thanks a million!