Hello I’m trying without succes to render the depth buffer to a texture.
Here is how i set up the Texture and the FBO:
//CREATE FB TEXTURE
glGenTextures(1, &m_FBOdepth_textura);
glBindTexture(GL_TEXTURE_2D, m_FBOdepth_textura);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 1280, 720, 0,GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0);
//CREATE FBO AND ATTACH TEXTURE TO IT
glGenFramebuffers(1, &m_FBO);
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, m_FBOdepth_textura,0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
// check FBO status
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
cout<<"FBO NO OK!!"<<endl<<endl;
// switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Then my render loop looks like this:
void Test10::Render()
{
glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_GL_program->Use();
m_textura->Bind();
m_textura_normalmap->Bind();
//SET UNIFORMS
m_GL_program->SetUniform("textura",0);
m_GL_program->SetUniform("normal_map",1);
vec3 pos_llum = vec3(m_llum->GetPosition());
m_GL_program->SetUniform("pLight",value_ptr(pos_llum),3,1);
m_stack.LoadIdentity();
mat4 identitat = m_stack.Top();
m_GL_program->SetUniformMatrix("ModelToWorld",value_ptr(identitat),4,4,false,1);
//RENDER MESH
m_mesh->Render(m_GL_program);
//FINISH
m_GL_program->UnUse();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
But when I check with gDEBugger the contents of the FBO texture it’s completely white… anyone can see wrong things there? (If I use the default framebuffer i can see the whole mesh correctly, and the FBO completeness is OK)
Oh and another question, have I to change the fragment shader in order to render to the depth buffer? I think it’s only with color_atachments… no?
Thank you