I have multi textures, A was drawed on top of B, B was on top of C ...., ( like Picture 1) .I want to fade out A first, then B will appear and fade out either... But when A fade out, background color appeared on top of B, ( like Picture 1 )? Why? What should I do? I have enable Blend like this
glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
and Fragment shader
"void main(void) { // 2\n"
"gl_FragColor = texture2D(Texture, TexCoordOut);\n"
"gl_FragColor *= alpha;\n"
" }\n"
Picture 1: background color is green, A and B are both rectangle, A is on top of B
Picure 2 When I fade out A, the result like this:
I aso try to use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
but it doesn't work either.
**Update 1 shader **
const GLchar *vertex_shader_source_ = { attribute vec4 Position;
uniform mat4 Projection;
uniform mat4 Modelview;
varying vec4 DestinationColor;
attribute vec2 TexCoordIn; // New
varying vec2 TexCoordOut; // New
void main(void) {
gl_Position = Projection * Modelview *Position;
TexCoordOut = TexCoordIn;// New
"}
};
const GLchar *fragment_shader_source_ = { uniform highp float alpha; uniform sampler2D Texture;// New
varying highp vec2 TexCoordOut; // New
void main(void) { // 2
gl_FragColor = texture2D(Texture, TexCoordOut);
"gl_FragColor.a = alpha;
} };