I have a background picture,shown by using openGL 2.0. Now I want to set the picture's alpha value.but I failed.
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1);
GLES20.glBlendFunc(GLES20.GL_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
GLES20.glEnable(GLES20.GL_BLEND);
.......
}
@Override
public void onDrawFrame(GL10 gl)
{
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glUniform1i(mTextureUniformHandle0, 0);
// Bind the texture to this unit.
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle0);
// Set the sampler texture unit to 0, where we have saved the texture.
GLES20.glUniform1f(mTextureAlpha, 0.5f);
// Draw the triangle
GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length, GLES20.GL_UNSIGNED_SHORT,
drawListBuffer);
}
Here is my fragment shader
precision mediump float;
uniform sampler2D u_Texture;
varying vec2 v_TexCoordinate;
uniform float myAlpha;
vec4 color;
void main()
{
color = texture2D(u_Texture, v_TexCoordinate);
gl_FragColor = vec4(color.rgb, color.a * myAlpha);
}
It seems that the color.a * myAlpha does not work.I don't know where my code wrong! Is there any limit to set alpha value?