Simple Blend question

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.

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).]

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?

try commenting this out

glColor3f(1,1,1)

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.

Ok give me a few mins I’ll try and tweak it. Keep checking back here.

Ok I only see the one triangle

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).]

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.

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.

That was the problem relic! thanks to you all. That works.