I’m having a hard time writing to an integer framebuffer using shaders. I’m able to create the integer texture just fine, but the problem is how to write the pixel shader to output correct values.
Here’s my initialization code:
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA32UI_EXT, gltClientWidth(), gltClientHeight(), 0, GL_ALPHA_INTEGER_EXT, GL_UNSIGNED_INT, 0);
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
Here are my shaders:
Vertex
#version 130
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Fragment
#version 130
out uint gl_PixelColor;
void main()
{
gl_PixelColor = 25;
}
And here’s my rendering code.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glClearColorIuiEXT(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program);
float colors[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
};
float vertices[] = {
0.0f, 0.0f,
100.0f, 0.0f,
100.0f, 100.0f,
0.0f, 100.0f
};
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, 0, colors);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_QUADS, 0, 4);
So what I would expect is for the bound integer alpha texture to contain a value of 25 wherever the quad was drawn. But instead, the entire texture stays completely black.
I know a lot of things became deprecated with GLSL 1.3, but I can’t seem to find good documentation on how to write shaders correctly, ect…
So overall, all I want to do is write values to an integer texture using pixel shaders.