I am learning OpenGL and have successfully created and displayed a GL_RGBA32F texture. Now I’m trying to create a GL_RGBA16UI texture, fill it with the color red in a compute shader and then display it on a screen quad. All I get is a black window and I have no idea what is wrong.
C++ snippet:
unsigned int texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
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_RGBA16UI, 512, 512, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
glBindImageTexture(0, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16UI);
Compute Shader:
#version 430 core
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
// image
layout (rgba16ui, binding = 0) uniform uimage2D img;
void main() {
ivec2 texelCoord = ivec2(gl_GlobalInvocationID.xy);
uvec4 texCol = uvec4(65535, 0, 0, 65535);
imageStore(img, texelCoord, texCol);
}
Fragment Shader:
#version 430 core
out vec4 FragColor;
in vec2 TexCoords;
uniform usampler2D tex;
void main()
{
uvec4 texCol = texture(tex, TexCoords);
FragColor = texCol;
}
Thank you in advance.