OpenGL ES 2.0: Vertex and Fragment Shader for 2D with Transparency
- by Bunkai.Satori
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);
}