Skip to main content
GameDev.net gamedev.net
🔒 Locked

FBO problem with depth_test

Started by kadd Oct 16, 2006 at 10:53 AM 7 replies 2k views
Original Post
kadd
kadd
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
RPTD
RPTD
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.
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine
kadd
kadd
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);
}
...
RPTD
RPTD
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 );		}	}
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine
kadd
kadd
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?
RPTD
RPTD
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 ).
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine
kadd
kadd
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...
kadd
kadd
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?

RPTD
RPTD
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.
Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.