OpenGL provides a variety of mixed methods, so we can easily achieve image mixing, such as overlay and brightening.
We know that generally, images with transparency are stored through four rgba channels. The most common glblendfunc is
Glblendfunc (gl_src_alpha, gl_one_minus_src_alpha)
Most of the information will tell you to use this to process translucent images, because:
Colorresult = srccolor * srcalpha + dstcolor * (1-srcalpha ).
Then srcalpha is resolved to transparency.
However, in reality, we may find that the half-Transparent area is grayed out when a translucent PNG image is drawn in most cases.
If you view the PNG image data you have loaded, you will find that the original PS is shown:
0 xffffffff, 0xffffff77, 0xffffffff00
When loaded, it becomes:
0 xffffffff, 0x77777777, 0x00000000
This is because you use premultiplied Alpha when loading images. Premultiplied Alpha pre-allocates Channel A in rgba to the color channel.
For example, the actual value of three rgba values is:
(1.0, 0.5, 0.0, 1.0)
(1.0, 0.5, 0.0, 0.5)
(1.0, 0.5, 0.0, 0.0)
After premultiplied Alpha processing, it indicates:
(1.0, 0.5, 0.0, 1.0)
(0.5, 0.25, 0.0, 0.5)
(0.0, 0.0, 0.0, 0.0)
All color channels are multiplied by the Alpha factor. In fact, what premultiplied Alpha does is the srccolor1 = srccolor0 * srcalpha operation.
In this way, the operations to perform semi-transparent mixing should be:
Colorresult = srccolor1 + dstcolor * (1-srcalpha ).
That is: glblendfunc (gl_one, gl_one_minus_src_alpha)
OpenGL translucent images produce a black halo