Don’t get transparency when displaying an image with RGBA in OpenGL

  alpha, c++, image, opengl

I’m currently implementing a small GUI in OpenGL. I’m displaying all elements (buttons, labels etc.) as textures/images of different sizes at the appropriate place. For that I load the textures/images onto the GPU and do seperate draw-calls for each element. Everything works fine so far using RGB-values (unsigned char/byte arrays), but now I wanted to implement this with RGBA-values (for example to make rounded buttons). I changed the arrays (from width * height * 3 – RGBRGBRGB… – to width * height * 4 – RGBARGBARGBA…), put GL_RGBA instead of GL_RGB in "glTexImage2D" and changed the fragment shader:

#version 430 core
in vec2 UV;
out vec4 color;
uniform sampler2D Sampler;
void main(
{
color = texture(Sampler, UV).rgba;
}

But everything looks the same – no transparency. What am I getting wrong? Is it because of seperate draw-calls (no data of what’s "behind" to show transparency)? For testing, if the image-data is correct I tried "color = texture(Sampler, UV).rgb * texture(Sampler. UV).a" (with "out vec3 color;") and the image was darker as expected (I set alpha to 100).

Source: Windows Questions C++

LEAVE A COMMENT