views:

499

answers:

1

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

alt text

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.

A: 

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