Sign in to follow this  
bbliksted

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
I am quite sure, that you don't attach a depth renderbuffer correctly. See the examples in the FBO spec for sample code to do that.

PS: Use the "code"-tag next time!

Share this post


Link to post
Share on other sites
This is a GL specific question and belongs to the GL forum.

Anyway,
you have to attach a depth renderbuffer or texture to your FBO in order to get a depthbuffer for testing.

e.g.:

glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, texobj_id, 0 );

or:

glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb_obj_id_ );


NOTE:
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, texture);

that wont work as well. check for gl error. you cant use a texture as a renderbuffer.


regards,
stephan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this