Results 1 to 3 of 3

Thread: Problem with blending,imposing of translucent polyg on solid

  1. #1
    Junior Member
    Join Date
    Sep 2005
    Posts
    2

    Problem with blending,imposing of translucent polyg on solid

    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:

    Code :
    	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:

    Code :
    	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:


    Code :
    	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
    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.

  2. #2
    Junior Member
    Join Date
    Jun 2005
    Location
    Espoo, Finland
    Posts
    6
    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.

  3. #3
    Junior Member
    Join Date
    Sep 2005
    Posts
    2
    tksuoran.
    don't work

    How I can change my code?

Similar Threads

  1. Problem in blend texture to draw translucent line
    By anoop.singh.knit in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 0
    Last Post: 12-26-2011, 12:09 AM
  2. blending problem
    By 0stress in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 3
    Last Post: 09-21-2006, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •