I’m trying to create alpha blending on textures, but I can’t get it to work.
I have a texture with alpha channel, compressed with DXT5 (I’ve tried 3 and 1 as well). Texture is loaded with SOiL.
Blending functions are
glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Shader: out vec4 outColor; ... outColor = min(vec4(col * scatteredLight + reflectedLight, texcol.a), vec4(1.0f, 1.0f, 1.0f, texcol.a));
Which gives me this result:
The pavement should have smoothed edge that blends with the grass texture behind it. It turned out that the gray color that should be transparent is the color that I’m using to clear the scene (it’s cleared once per drawing loop).
I tried to see if the alpha is sent correctly, so I changed the code in shader a little bit to
outColor = vec4(1.0f, 1.0f, 1.0f, texcol.a);
Which gave me
That shows us the alpha is actually there.
Strange thing is the text in upper left and cursor are rendered correctly, while the only difference is that it is drawn after all the meshes are drawn, and it uses glDrawArrays instead of glDrawElements (that meshes use). I tried to draw the font picture on the mesh, but the result was the same - gray background instead of proper blending.
If it matters, the pavement and the grass are two separate meshes.
What could I miss?