Render to depth textures and FBO

Hi,

I was trying to do some FBO stuffs. I succeeded to make them work for simply doing some rendering offscreens, and use that as a texture inside the on-screen rendering.

So I decided to try to make an off-screen rendering of the depth into a texture via FBO.

OpenGL outputs an error when I call to render the scene.

The RBO (render to buffer object) and the FBO are well initialized (normally). The rbo is set for DEPTH_COMPONENT, the texture created with both format and internal format to DEPTH_COMPONENT, and I attach the rbo to the fbo with setting DEPTH_ATTACHMENT_EXT.

The rendering code uses some colors, lighting, materials but I’m pretty sure the problem is not there.

Anyone has any hints ?

EDIT:

I don’t know what GL error it could be, just its value: glGetError returns 1286 (506 in hexa). gluErrorString doesn’t print anything from this error and I couldn’t find it in the headers.

I found this is invalid fbo operation but that doesn’t help me more.

#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT   0x0506

Did you call glDrawBuffer(GL_NONE) and glReadBuffer(GL_NONE)?

I’ve tried both with no real solutions.

More things:

I created an fbo and an rbo once, before rendering, setting for depth texture. I checked fbo completeness just after and I got an incomplete read buffer. So I surely missed something but I can’t figure out what it could be.

I think there’s something about the need to have a color rbo along with a depth one for the same fbo. But I’m not sure at all.

Thanks.

no, no need to have color heres what i do, u need a valid depth texture setup for it to work.
check out example 7 in the spec also (its in the new space not the old one that only had examples 1-6)

shadowMap_textureID = g_rm.textureLIB.givemeTexture( tex, GL_CLAMP_TO_BORDER, GL_LINEAR, GL_LINEAR, GL_DEPTH_COMPONENT16 );

	if ( GL_EXT_framebuffer_object_supported )
	{
		shadow_fbo.init_depthbuffer_FBO( shadowMap_textureID );
		has_shadow_fbo = true;
	}

GLuint OpenGL_FBO::init_depthbuffer_FBO( GLuint depth_texID )
{
using_textureID = depth_texID;

glGenFramebuffersEXT( 1, &framebufferID );
bind_fbo( );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, using_textureID, 0 );

glDrawBuffer( GL_NONE );
glReadBuffer( GL_NONE );

check_framebuffer_status();

unbind_fbo();
return framebufferID;

}

void OpenGL_FBO::bind_fbo( void )
{
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, framebufferID );
}

void OpenGL_FBO::unbind_fbo( void )
{
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
}

I checked fbo completeness just after and I got an incomplete read buffer.
Make sure you check for completeness AFTER calling glReadBuffer(GL_NONE).

Doing so clames this is unsupported when checking for the FBO.

Here is how I do that:

glGenTextures (1, &map_tex);
glBindTexture (GL_TEXTURE_2D, map_tex);
glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, tex_size, tex_size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE,0);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBindTexture (GL_TEXTURE_2D, 0);

fbo.Generate();
fbo.Bind();
fbo.Texture2D (map_tex, GL_DEPTH_ATTACHMENT_EXT);

glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

fbo.Check();
fbo.Unbind();

My code really looks the same as yours and as the example number 7 from the specs. I also tried again to attach a renderbuffer but still with no success. What’s strange is that ‘normal’ FBO are working great (I mean using the FBO as a color texture).

Could it be an hardware/driver issue ? (geforce Fx 5600, nv 7667, linux)

I would say it’s from my hardware/driver.

I tried the way of using a color logical buffer attached to the fbo along with the texture and now it works fine. But I must admit I’d prefer to use them without adding ‘unnecessary’ features.

Specs says that for an FBO to be completed it depends on several things: GL things plus some vendor requirements. Can this (redundant) problem comes from that ? Or is it more from a driver issue/bug ?

So you have both color_attachment0 and depth_attachement to seperate texture objects at once ?

Reason i’m asking is that i can only get depth_attachment to work if i don’t attach anything to color_attachment0.

I tried modifing nvidia code sample “Simple Framebuffer Object” to use a texture object instead of a renderbuffer for depth_attachment but as i said i can’t make it render both depth and color buffers to textures at once.

Try a specific internal format like GL_DEPTH_COMPONENT16 or 24. The generic format doesn’t work for some reason…

Thanks that worked :slight_smile:

I’m just gonna post the line so people can google it :slight_smile:

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, texWidth, texHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

Originally posted by FlipFlop:
[b]Thanks that worked :slight_smile:

I’m just gonna post the line so people can google it :slight_smile:

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, texWidth, texHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);[/b]
I faces some issues when trying to use them, like unsupported format or so. I’m gonna look at that again and maybe post later.

Originally posted by FlipFlop:
[b]So you have both color_attachment0 and depth_attachement to seperate texture objects at once ?

Reason i’m asking is that i can only get depth_attachment to work if i don’t attach anything to color_attachment0.

I tried modifing nvidia code sample “Simple Framebuffer Object” to use a texture object instead of a renderbuffer for depth_attachment but as i said i can’t make it render both depth and color buffers to textures at once.[/b]
It seems that having a renderbuffer color attached to a FBO that also has a texture buffer attached to it only fills in the depth data into the texture.

Overmind, I tried many things with specifying different sizes but with no success.

Regarding to what I understood from the specs, one should have the same behavior without using any renderbuffer at all but only an attached texture.

Actually, what I’d like to know, is that if some people succeeded to make that working (without renderbuffer) under Linux.

zed, have you heard of c++?