Jump to content
  • Advertisement
Sign in to follow this  
kadd

FBO problem with depth_test

This topic is 4383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I am trying to use fbo's to render an object directly into a texture. This works fine except that the depth_test seems to be disabled. Is there any way to enable the depth_test while rendering into the texture? I've allready tried to attach an renderbufferObject for the depth but the texture seems to be totaly wrong after that. Here is my code: glewInit(); //check if framebuffer objects are supported fbo = glewGetExtension("GL_EXT_framebuffer_object");//fbo = false; //if framebuffer objects are supported, create one for the gbuffer if (fbo) { glEnable(GL_DEPTH_TEST); glGenFramebuffersEXT(1, &fb); } ... if (fbo) { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glEnable(GL_DEPTH_TEST); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0); } ... /*draw something*/ Can anyone help me? I am using fbo's for the first time so maybe there is just a little mistake. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Can you post the code where you attacjed the depth renderbuffer? This code up there won't work as you enable depth test but there is no depth buffer assigned ( framebuffer incomplete ). The result of such a combination is undefined by specs.

Share this post


Link to post
Share on other sites
Do I have to attach the renderbuffer? Is there no way just to attach a texture an draw into the texture with depth_test enabled? Anyway here is the hole code with the renderbufferObject:

if (fbo)
{
glEnable(GL_DEPTH_TEST);
//create framebuffer and renderbuffer
glGenFramebuffersEXT(1, &fb);
glGenRenderbuffersEXT(1, &rb);
}
...
glBindTexture(GL_TEXTURE_2D, texture);
//attach texture to framebuffer color buffer, if fbo is supported
if (fbo)
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glEnable(GL_DEPTH_TEST);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, windowSizeX, windowSizeY);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb);
}
...

Share this post


Link to post
Share on other sites
No, you can use only a texture without depth buffer but then you have to disable depth testing. If you want to use depth testing you have to provide some storage in form of a texture or a renderbuffer as the FBO itself does not allocate such a thing for you. The same goes for the stencil buffer.

Now to the code. Can you please do a framebuffer check and tell me what it says? ( It may be a 'unsupported format' I suppose ).

	GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
if( status != GL_FRAMEBUFFER_COMPLETE_EXT ){
if( status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT ){
printf( "FBO: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n" );
}else if( status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT ){
printf( "FBO: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n" );
}else if( status == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT ){
printf( "FBO: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n" );
}else if( status == GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT ){
printf( "FBO: GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n" );
}else if( status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT ){
printf( "FBO: GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n" );
}else if( status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT ){
printf( "FBO: GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n" );
}else if( status == GL_FRAMEBUFFER_UNSUPPORTED_EXT ){
printf( "FBO: GL_FRAMEBUFFER_UNSUPPORTED_EXT\n" );
}else{
printf( "FBO: Unknown Error Code %i!\n", status );
}
}

Share this post


Link to post
Share on other sites
I allready did the test a couple of times and it always sais GL_FRAMEBUFFER_COMPLETE_EXT. But I am sure that something must be wrong with the renderbufferObject. If I attach this object or better if I use the function glFramebufferRenderbufferEXT the texture gets totaly wrong. It is really noise after that.

And without the renderbufferObject the texture seems to be correct if it is normal that there is no depth testing. So maybe I have to allocate some space for the depthtest?

Share this post


Link to post
Share on other sites
Ok, do once the following.

Before the attach-texture line add two lines setting the texture filtering ( MIN, MAG ) to GL_NEAREST.

Then at the line with the enable depth test also specify the test type ( GL_LEQUAL ). Then before rendering be sure to make a glClear with the depth bit specified.

Let's see what this does ( or if you have it already ).

Share this post


Link to post
Share on other sites
Hmm,

I tried that before.. There is no difference. If I use the renderbufferObject the texture ist totaly wrong. Maybe I have to allocate memory for that or something like that...

Share this post


Link to post
Share on other sites
ok,

maybe this helps: if I disable the depth_test with the same code the texture looks fine. Except that the depth_test is disabled... any ideas what goes wrong with my renderbufferObject?

Share this post


Link to post
Share on other sites
No usually the depth renderbuffer doesn't mess things up at all. But maybe your GL_DEPTH_COMPONENT24 is not well. Depending on what card you run this on it can backfire on you. Tried once with GL_DEPTH_COMPONENT only?

Furthermore I think more that something is wrong with your rendering code as the entire setup there looks ok ( and mostly like what I have and this works ).

Can you post an image of "how" disorted the texture looks? This could help determine what goes wrong.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!