OpenGL ES 2.0: Vertex and Fragment Shader for 2D with Transparency

Posted by Bunkai.Satori on Game Development See other posts from Game Development or by Bunkai.Satori
Published on 2011-02-25T17:22:52Z Indexed on 2011/02/25 23:34 UTC
Read the original article Hit count: 550

Could I knindly ask for correct examples of OpenGL ES 2.0 Vertex and Fragment shader for displaying 2D textured sprites with transparency?

I have fairly simple shaders that display textured polygon pairs but transparency is not applied despite:

  • texture map contains transparency information
  • Blending is enabled: glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

My Vertex Shader:

uniform mat4 uOrthoProjection;
uniform vec3 Translation;

attribute vec4 Position;
attribute vec2 TextureCoord;

varying vec2 TextureCoordOut;

void main()
{
    gl_Position = uOrthoProjection * (Position + vec4(Translation, 0));
    TextureCoordOut = TextureCoord;
}

My Fragment Shader:

varying mediump vec2 TextureCoordOut;
uniform sampler2D Sampler;

void main()
{
    gl_FragColor = texture2D(Sampler, TextureCoordOut);
}

© Game Development or respective owner

Related posts about opengl

Related posts about opengl-es