# Opengles 2.0 multi Textures fade out one by one

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;


} };

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

## 1 Answer

Try with

glDisable(GL_DEPTH_TEST);


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

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

• 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. – user2803729 Dec 29 '15 at 9:24
• 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 – Stephane Hockenhull Dec 29 '15 at 18:37