PDA

View Full Version : Simple Blend question



DraKKaR
08-07-2003, 01:36 PM
every frame I execute these:

glEnable(GL_BLEND);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);

glBlendFunc(GL_ONE,GL_ZERO);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glBegin(GL_TRIANGLES);
glColor4f(1.0f,0.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor4f(0.0f,1.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor4f(0.0f,0.0f,1.0f,0.5f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();


glBlendFunc(GL_DST_ALPHA,GL_ZERO);
glColor3f(1,1,1);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
The result is a white triangle. But I do not understand why! each color of second triangule should be multiplied by the alpha of the first triangle, but it doesn't.

c0d3Junk3Y
08-07-2003, 01:47 PM
Stupid question from me but you do know about the line you have commented out right?



glBlendFunc(GL_ONE,GL_ZERO);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

[This message has been edited by c0d3Junk3Y (edited 08-07-2003).]

DraKKaR
08-07-2003, 01:58 PM
Yes... the whole code is right. But it does not do what it should, in my eyes.

Why that code gives me a white triangle?

c0d3Junk3Y
08-07-2003, 02:02 PM
try commenting this out


glColor3f(1,1,1)

DraKKaR
08-07-2003, 02:09 PM
Why? The only thing it would change is the color of the second triangle. I commented that but I does not work. The second triangle is rendered in blue, But I think it should multiply that blue by the previous triangle's alpha.

c0d3Junk3Y
08-07-2003, 02:11 PM
Ok give me a few mins I'll try and tweak it. Keep checking back here.

c0d3Junk3Y
08-07-2003, 02:35 PM
Ok I only see the one triangle

c0d3Junk3Y
08-07-2003, 02:44 PM
I got a colored triangle on the left and a white one on the right


Check out http://nehe.gamedev.net Lesson 2

[This message has been edited by c0d3Junk3Y (edited 08-07-2003).]

DraKKaR
08-08-2003, 12:18 AM
Left? Right? I think you do not understand me. I am painting 2 triangles, one over the other one with a blending function. The problem is: the color of the final triangle seems to be wrong, because I get a white triangle and it should be a grayscaled triangle.

Please, read the code in my first post and tell me which color should have the final triangle when rendered.

Relic
08-08-2003, 12:56 AM
You have verified that you have requested and actually gotten a pixelformat with destination alpha channel?
If not, the glBlendFunc(GL_DST_ALPHA,GL_ZERO); will always use 1.0 for alpha.

DraKKaR
08-08-2003, 05:06 AM
That was the problem relic! thanks to you all. That works.