My texture has a single channel only, however I can’t seem to change its contents other than at the time of creation:
glDisable(GL_DEPTH_TEST);
unsigned int frameBuffer;
glGenFramebuffers(1,&frameBuffer);
unsigned int texture;
glGenTextures(1,&texture);
glBindFramebuffer(GL_FRAMEBUFFER,frameBuffer);
int w = 256;
int h = 256;
unsigned char *pixels = new unsigned char[w *h];
for(unsigned int i=0;i<(w *h);i++)
pixels[i] = 128;
glTexImage2D(
GL_TEXTURE_2D,0,
GL_ALPHA16,w,h,
0,GL_ALPHA,
GL_UNSIGNED_BYTE,
&pixels[0] // Works fine
);
delete[] pixels;
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texture,0);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
glDeleteTextures(1,&texture);
return;
}
glClearColor(1,1,1,1);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT); // Has no effect
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glClearColor(0,0,0,1);
glEnable(GL_DEPTH_TEST);
Even after the glClear-Call the content of the frame buffer is still the same as what I’ve initialized it with (128 for each pixel). And yes, the frame buffer status reports as complete. Trying to write anything to it via shader has no effect either:
// Fragment shader
#version 330 core
in vec2 uv;
out float color;
uniform sampler2D tex; // The generated alpha-texture from above
void main()
{
color = 1.f;
}
glGetError doesn’t report any errors anywhere. I’m using OpenGL 4.4.
Am I missing something here?