Transparent parts of texture are opaque black instead

Posted by Aaron on Game Development See other posts from Game Development or by Aaron
Published on 2012-07-10T14:48:00Z Indexed on 2012/07/10 15:26 UTC
Read the original article Hit count: 230

Filed under:
|
|

I render a sprite twice, one on top of the other. The sprites have transparent parts, so I should be able to see the bottom sprite under the top sprite. The transparent parts are black (the clear colour) and opaque instead though and the topmost sprite blocks the bottom sprite.

My fragment shader is trivial:

uniform sampler2D texture;
varying vec2 f_texcoord;
void main()
{
    gl_FragColor = texture2D(texture, f_texcoord);
}

I have glEnable(GL_BLEND) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) in my initialization code. My texture comes from a PNG file that I load with libpng. I'm sure to use GL_RGBA when initializing the texture with glTexImage2D (otherwise the sprites look like noise).

© Game Development or respective owner

Related posts about opengl

Related posts about textures