Problem with blending,imposing of translucent polyg on solid

System: Symbian 60
OpenGLES: 1.0 (!)
Language: C++


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;

	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;

	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;


	glColorPointer(4, GL_FLOAT, 0, iBlendColorBuffer);

I draw a rectangle (2 polygons) without using transparency:


	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:


	glBindTexture(GL_TEXTURE_2D, iTexture2ID);	
	glDrawElements(GL_TRIANGLES, 3*2, GL_UNSIGNED_SHORT, iBlendIndexBuffer);


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

  1. first draw the solid rectangle
  2. 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.

The code does not show how you set texture env. I think you should have glTexEnvi(GL_TEXTURE_ENV_MODE, GL_MODULATE), for the latter, and glTexEnvi(GL_TEXTURE_ENV_MODE, GL_REPLACE) for the first. With GL_REPLACE your call glColor4f(1.0f, 1.0f, 1.0f, 1.0f); is not needed.

The default value should be GL_MODULATE though, so that may explain why your code works on desktop.

don’t work :cry:

How I can change my code?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.