PDA

View Full Version : Correct Parameter For glBlendFunc Function



susanne
03-20-2014, 01:14 PM
Hi!!!

I've got a question about the glBlendFunc. How do i have to choose the parameters to get this result:

Image1 (s7.directupload.net/images/140320/ly6qmfmn.png)
Image2 (s7.directupload.net/images/140320/qtl2ffsi.png)
Blending (s1.directupload.net/images/140320/cg7w89rb.png)

greetz

Cornix
03-20-2014, 01:22 PM
I dont see any blending being done in that picture. You just draw image2 on top of image1.

susanne
03-20-2014, 01:26 PM
Is this not blending, where alpha = 0?

Ist that not possible with glBlendFunc in general?

My idea was to do this overlay by using glBlendFunc. The Image2 should be a texture with alpha channel.

Brokenmind
03-20-2014, 01:34 PM
Usually, these two lines should do the trick:



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

And yes, this is blending because otherwise, the white background would cover all the stars, which it does not due to alpha=0.

Cornix
03-20-2014, 01:35 PM
What you want is probably disabled blending with an Alpha-Test.
Alpha-Test will cull all fragments where the alpha value does not satisfy the test.

susanne
03-20-2014, 01:44 PM
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


That seems to work. Thank you Brokenmind :angel:.


What you want is probably disabled blending with an Alpha-Test.
Alpha-Test will cull all fragments where the alpha value does not satisfy the test.

How can i implement this? Or is this only possible with a fragment shader?

Cornix
03-20-2014, 02:00 PM
With the blending provided by Brokenmind it will work too. If you want to do it without blending (because you really dont need blending if you only use alpha values of 1 and 0) then you can do:


glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1);

This will make it so that only those fragments with an alpha value of exactly 1 will be drawn. All other fragments will be discarded.