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

enter image description here

Picure 2 When I fade out A, the result like this:

enter image description here

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;

} };

  • \$\begingroup\$ Could you share the entire shader code ? I understand you have 3 different quads and not one quad with three textures, can you confirm? \$\endgroup\$ Dec 28, 2015 at 10:49
  • \$\begingroup\$ @ elenfoiro78 I had updated the question. \$\endgroup\$ Dec 29, 2015 at 9:06

1 Answer 1


Try with


And render the images in back-to-front order.

Most likely the depth test is what's preventing the other images from rendering.

  • \$\begingroup\$ Yes, It's oK now, thank you. But I don't know why? if A is on top of B, when I enable depth test, draw in order B->A, then A is not visible, If I disable depth test, A will appear again. can you tell me why? thanks. \$\endgroup\$ Dec 29, 2015 at 9:24
  • \$\begingroup\$ The depth test is usually used to prevents drawing pixels behind (or equal) to other pixels. See en.wikipedia.org/wiki/Z-buffering and opengl.org/wiki/Depth_Test \$\endgroup\$ Dec 29, 2015 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .