Hi! I created a 2d texture with internal format GL_DEPTH_COMPONENT
and attached it to my frame buffer as GL_COLOR_ATTACHMENT1
:
glGenTextures(1, &m_nId);
glBindTexture(GL_TEXTURE_2D, m_nId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_nWidth, m_nHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
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_COMPARE_MODE, GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_nId, 0);
I don’t use this texture for depth testing, so I don’t need to use GL_DEPTH_ATTACHMENT
(I have another texture for that purpose).
Now, I am trying to write the texture from a simple fragment shader:
//Already bound my frame buffer
glDrawBuffer(GL_COLOR_ATTACHMENT1);
fragment code:
#version 330 core
in vec4 color;
layout (location = 0) out float Depth;//I have tried also with vec3
void main()
{
Depth = gl_FragCoord.z;//I have tried also with vec3(gl_FragCoord.z)
//scrivo sul depth buffer per effettuare il test
gl_FragDepth = gl_FragCoord.z;
}
My GL_COLOR_ATTACHMENT1
is always dark, it seems I cannot write on it.
Plus I cannot clear the color attachment with:
//Framebuffer bind
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
My GL_COLOR_ATTACHMENT1
is still black.
I think I am messing up with the internal format (GL_DEPTH_COMPONENT
).
I appreciate any helps