View Full Version : glFramebufferTexture2D with depth or stencil textures

02-08-2013, 05:58 AM
I am using glFramebufferTexture2D and have some doubts regarding it:
1) With Depth render able formats, we attach texture as depth component attachment so how do we render color image with depth attachment?
2) How to render colored image with stencil attachment?

02-08-2013, 06:08 AM
you can have several color-attachments, depth-attachment and stencil-attachment simultaneously. take a look at these examples:
https://www.opengl.org/wiki/Framebuffer_Object_Examples#Color_texture.2C_Depth _texture
https://www.opengl.org/wiki/Framebuffer_Object_Examples#Quick_example.2C_rende r_to_texture_.282D.29.2C_mipmaps.2C_depth_stencil

and ask if you cant figure out something.

02-08-2013, 08:23 AM
What do you mean "render color with depth attachment(stencil)"?

02-08-2013, 08:48 AM
What do you mean "render color with depth attachment(stencil)"?
Depth texture stores only depth values and so we attach this to FBO but when we attach this non default FBO to system fbo as a texture where do the color values come from, i mean as we dont have any color attachment, how to draw this depth texture ??

02-08-2013, 10:42 AM
Your not making much sense here. There isno such thing as a system FBO, there is only the default framebuffer, which is window system provided and has nothing to do with FBOs. Actually, I think I already told you so in another thread IIRC. So once and for all: There is no default or window system provided FBO. Also, you cannot attach anything to the default framebuffer. Period.

Second, having a depth texture and one or more color attachments are different things - and in the following I'm only talking about core GL without any legacy stuff. Writing to color attachments happens via fragment shaders. Fragment shaders are not run, if the depth test discards a fragment. To be able to actually do a depth test, there needs to be a depth buffer attached to the FBO. Depth values are automatically generated - you don't need to do anything for that. The depth attachment will be updated automatically when you render stuff and newly rasterized fragments pass the depth test (i.e. the depth attachment is updated). I'm not exactly sure right now what happens if the depth test is enabled and there is no depth attachment on your FBO, but I suspect it works anyway. You can write depth values from a fragment shader as well, using gl_FragDepth. This will write depth values to your depth attachment not to any color attachment.

What's your use-case? What do you want to achieve? Shadow mapping, by any chance?