System: Symbian 60
OpenGLES: 1.0 (!)
Language: C++
Hello
We need to blend two textures with defined alpha level.
I perform the following (simple example):
First, I set the data that we will need later:
float iBlendVertexBuffer[4*3];
iBlendVertexBuffer[0] = 20.0f;
iBlendVertexBuffer[1] = 0.0f;
iBlendVertexBuffer[2] = -5.0f;
iBlendVertexBuffer[3] = 20.0f;
iBlendVertexBuffer[4] = 10.0f;
iBlendVertexBuffer[5] = -5.0f;
iBlendVertexBuffer[6] = 20.0f;
iBlendVertexBuffer[7] = 10.0f;
iBlendVertexBuffer[8] = 5.0f;
iBlendVertexBuffer[9] = 20.0f;
iBlendVertexBuffer[10] = 0.0f;
iBlendVertexBuffer[11] = 5.0f;
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, iBlendVertexBuffer);
float iBlendTextureBuffer[4*2];
iBlendTextureBuffer[0] = 0.0f;
iBlendTextureBuffer[1] = 0.0f;
iBlendTextureBuffer[2] = 1.0f;
iBlendTextureBuffer[3] = 0.0f;
iBlendTextureBuffer[4] = 1.0f;
iBlendTextureBuffer[5] = 1.0f;
iBlendTextureBuffer[6] = 0.0f;
iBlendTextureBuffer[7] = 1.0f;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, iBlendTextureBuffer);
GLushort iBlendIndexBuffer[3*2];
iBlendIndexBuffer[0] = 0;
iBlendIndexBuffer[1] = 2;
iBlendIndexBuffer[2] = 1;
iBlendIndexBuffer[3] = 0;
iBlendIndexBuffer[4] = 3;
iBlendIndexBuffer[5] = 2;
float iBlendColorBuffer[4*4];
iBlendColorBuffer[0] = 1.0f;
iBlendColorBuffer[1] = 1.0f;
iBlendColorBuffer[2] = 1.0f;
iBlendColorBuffer[3] = 0.5f;
iBlendColorBuffer[4] = 1.0f;
iBlendColorBuffer[5] = 1.0f;
iBlendColorBuffer[6] = 1.0f;
iBlendColorBuffer[7] = 1.0f;
iBlendColorBuffer[8] = 1.0f;
iBlendColorBuffer[9] = 1.0f;
iBlendColorBuffer[10] = 1.0f;
iBlendColorBuffer[11] = 0.5f;
iBlendColorBuffer[12] = 1.0f;
iBlendColorBuffer[13] = 1.0f;
iBlendColorBuffer[14] = 1.0f;
iBlendColorBuffer[15] = 0.0f;
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, iBlendColorBuffer);
I draw a rectangle (2 polygons) without using transparency:
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glDisableClientState(GL_COLOR_ARRAY);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, iTexture1ID);
glDrawElements(GL_TRIANGLES, 3*2, GL_UNSIGNED_SHORT, iBlendIndexBuffer);
Then I draw the same rectangle with the same coordinates, but with another texture and with set colors (with alpha-channel) on its apexes:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_COLOR_ARRAY);
glBindTexture(GL_TEXTURE_2D, iTexture2ID);
glDrawElements(GL_TRIANGLES, 3*2, GL_UNSIGNED_SHORT, iBlendIndexBuffer);
glDisable(GL_BLEND);
That’s the point!!! In OS Windows using OpenGL everything is drawn perfectly,
but in OpenGLES 1.0 for Symbian 60 the first (solid) rectangle is drawn always in foreground, and the second one (semi-transparent) - behind that. So in result there’s no overlay - there’s no smooth transition from one texture to another.
How do that?
We need
- first draw the solid rectangle
- draw the semi-transparent rectangle
e.g. we need everything, that has been drawn before semi-transparent object, to be located on a background and to serve as a base for calculation the proper color using alpha.