Jump to content
  • Advertisement
Sign in to follow this  
DallyLama

OpenGL FBO question

This topic is 3080 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

Hello All, I have a simple FBO question. I'm trying to implement a deferred shading using openGL. my question is this, if I attach to the FBO, in Color_attachment0, a Texture using the API line
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_FORMAT,480,800,0,GL_RED,GL_FLOAT,NULL);

This is done in order to render the Z-Buffer to a texture. In the fragment shader how do I output a single float to the image? does gl_fragColor is the same type has the texture format bound to the RT? Also if I later want to sample from that texture, does texture2D return type, is the format of the texture? If not, how do I change the type of the output of the fragment shader? Thanks all

Share this post


Link to post
Share on other sites
Advertisement
First, your call is wrong, it's GL_DEPTH_COMPONENT, not GL_DEPTH_FORMAT.

Answering your question, depth is output through gl_FragDepth, gl_FragColor is only for color buffers.

Share this post


Link to post
Share on other sites
You need to use
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT16,480,800,0,GL_RED,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,480,800,0,GL_RED,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT32,480,800,0,GL_RED,GL_FLOAT,NULL);

http://www.opengl.org/wiki/GL_EXT_framebuffer_object#Color_texture.2C_Depth_texture

=====For the shader
Normally, it is best not to write to gl_FragDepth because it disable hierarchal z and early z test. It will automatically output the default depth value of the fragment.

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!