2

I have a texture with transparency (the white triangle with that lighting information), and just can't make it's alpha variable.

alt text http://gotoandplay.freeblog.hu/files/alpha_help.png

The drawing code, with the missing piece:

  //Place polygon vertices to the bottom left within the view.
  glLoadIdentity();
  glTranslatef(centerX, centerY, 0);

  //Draw "diffuse" layer.
  glBindTexture(GL_TEXTURE_2D, spriteTexture[0]); //Bind.
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

  //Offset during development only.
  glLoadIdentity();
  glTranslatef(centerX-10, centerY+10, 0); 

  //Draw "specular" layer.
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, spriteTexture[1]); //Bind.

  //Some smart alpha scaling code needs here...

  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

Could somebody please help me out with the appropriate lines of code? Some glBlendFunc, or maybe glTextEnvi stuff I suppose.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
  • Can you write out the math of what how you want the values of the two textures to be blended together? (background + triangle1 + triangle2). Or, do you want to apply both textures to the same triangle? – Frogblast Feb 02 '10 at 05:14
  • The triangles are being rendedered into a separate framebuffer connected to a texture. So in this separate framebuffer the background is (0,0,0,0), the trianlge 1 is simply alpha blended, just like the second triangle (no any add, modulate, etc. like these). You can see these images (so the generated textures) in my previous question here: http://stackoverflow.com/questions/2173363/please-help-with-an-opengl-es-iphone-multi-texturing-2d-code – Geri Borbás Feb 02 '10 at 10:29

1 Answers1

0

Ok, I got it even if I don't understand what I did exactly.

    //Place polygon vertices to the bottom left within the view.
    glLoadIdentity();
    glTranslatef(centerX, centerY, 0);

//--1   

        //Draw "diffuse" layer.
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, spriteTexture[0]); //Bind.

            //Blending.
            glBlendFunc(GL_ONE, GL_ONE);

        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);  

//--2   

        //Draw "specular" layer.
        glBindTexture(GL_TEXTURE_2D, spriteTexture[1]); //Bind.

            //Blending.
            glColor4f(opacity, opacity, opacity, opacity);
            glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);

        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

I tried another way before...

glColor4f(1.0f, 1.0f, 1.0f, opacity);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

...but the second map was somehow "weaker".

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172