0
votes

I clear a framebuffer...

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);

...I enable blending as such...

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
[self render]
glDisable(GL_BLEND);

In that render code, I simply add a quad and draw it. In my fragment shader I have...

gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);

This yields a clear quad. Great. No color, no alpha, no nothing...got it. However, I change the fragment shader to...

gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);

I get the quad filled with white. Can someone explain to me how filling a quad with fully transparent red would yield opaque white, and not just clear?

1
Are you using depth buffer / depth testing?Ayan Sengupta
Well, you have GL_ONE as the first argument to glBlendFunc(). So you add the fragment color to the destination value, independent of the alpha value.Reto Koradi
@RetoKoradi right so the fragment color is (1, 0, 0, 0), and the destination color is (0, 0, 0, 0). Adding them together gives (1, 0, 0, 0), right? Why is it that a final value of (1, 0, 0, 0) renders as white? It seems to me it should be clear since the alpha value is 0, or at least some shade of red?Herm
@AyanSengupta I have depth testing disabled actually. Is that an issue?Herm
Yeah, you'd think it would be red.Reto Koradi

1 Answers

0
votes

doesn't GL_ONE_MINUS_SRC_ALPHA do

(1, 1, 1, 1) - (As/kA, As/kA, As/kA, As/kA)

so if As is 0 it will result in (1, 1, 1, 1)?

ED though I'm not clear why that has a different effect when you set your fragment to (1, 0, 0, 0) from (0, 0, 0, 0). I notice that I used

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

What do you get with different arguments to the blend function?