0
votes

Well, I'm Modding a 2D opensource Game Client and i was trying to add transparency to game objcts textures. Its already read and load the alpha channel. The textures are already loaded in openGL with format and internal format as RGBA.

The problem is, when the alpha channel of a pixel is below 255 (or 1) its just do not show up in the screen. Its not ignoring the alpha channel and showing only RGB, its HIDE the pixel. This client use OpenGL and shadders to drawing.

I already have enabled blending by calling: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ), glDisable(GL_DEPTH_TEST) and glColorMask(1,1,1,1).

1
Have you enabled alpha testing instead of alpha blending?JasonD
thank you for the comment. I have done a search in whole source code and do not have found anything enabling alpha testing.Cristofer Martins
What about the shaders - do they do a kill/discard?JasonD
no. the code of the shader is :Cristofer Martins
uniform float u_Time; uniform sampler2D u_Tex0; varying vec2 v_TexCoord; void main() { gl_FragColor = texture2D(u_Tex0, v_TexCoord); }Cristofer Martins

1 Answers

2
votes
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )

This line tells Open GL how to blend the source and destination pixels.

glDisable(GL_DEPTH_TEST)

I think this is where you might be going wrong as this disables the Z-DEPTH test which you shouldn't need for 2D rendering.

glColorMask(1,1,1,1)

I'm not 100% on this but I suspect that this hides any pixels that match the RGBA specified. In this case any pixel with R=255, G=255, B=255 and A=255 wont be rendered.

Try using:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

renderEverything();

glDisable(GL_BLEND);

Hope you can get it working :)