0
$\begingroup$

I don't understand how OpenGL performs the blending of a texture on the screen. By default, the clear color is set to (0, 0, 0, 0). If we use the default blending equation GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA, it means that if our texture is all (1, 0, 0, 0.3), the resulting RGB will be (1, 0, 0)×0.3 + (0, 0, 0)×0.7 = (0.3, 0, 0) BUT the alpha component will be 0.3×0.3 + 0×(1 - 0.3) = 0.3, so we then have a color of (0.3, 0, 0, 0.09) which is not correct, what we want to see on the screen is rather (0.3, 0, 0, 1).

So how does OpenGL manages the final blending with the framebuffer? Does it drop the alpha component (because the screen can only display RGB colors)?

$\endgroup$
2
  • 1
    $\begingroup$ "performs the blending of a texture on the screen." It doesn't. Fragments are blended with the screen. What that fragment data is is up to you and your fragment shader. It can be just a value fetched from a texture, but it doesn't have to be. $\endgroup$ Mar 17, 2021 at 15:03
  • 1
    $\begingroup$ Here is a link to a basic introduction to the topic if you want to learn more about alpha blending in OpenGL specifically: learnopengl.com/Advanced-OpenGL/Blending . And I am sure everyone in the community will be happy that I will not give one of my long winded explanations that just goes on and on.... $\endgroup$
    – pmw1234
    Apr 20, 2021 at 13:33

1 Answer 1

0
$\begingroup$

BUT the alpha component will be 0.3×0.3 + 0×(1 - 0.3) = 0.3, so we then have a color of (0.3, 0, 0, 0.09) which is not correct, what we want to see on the screen is rather (0.3, 0, 0, 1).

Your blending function did not use the destination alpha. So "correct" or "not correct", its value is entirely irrelevant.

However, if you want to make the alpha more accurate in some way, you can provide a different set of blending factors, and even a different blend equation, for the alpha component.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.