OpenGL translucent images produce a black halo

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.