FBO question

Started by
4 comments, last by DallyLama 14 years ago
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
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.
this means that FragData[] is vec4 type?
vec4 gl_FragData[], yes, but i was talking about gl_FragDepth, which is of type float.
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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ok thanks all

This topic is closed to new replies.

Advertisement