简体   繁体   中英

glBlendFunc and alpha channel

I'm trying to render some transparent objects using:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

However, I don't get the result I want.

I draw a fully opaque square, and then i draw a semi-transparent square. The colors are just as a I would expect however, the alpha channel is NOT fully white as I want.

Basically I want the following equation:

r = old_r*(1.0-a)+r*a;
g = old_g*(1.0-a)+g*a;
b = old_b*(1.0-a)+b*a;
a = old_a + a;

Is this possible to achieve using glBlendFunc or do I have to resort to shaders and multiple FBOs for read-back?

You basically want separate blend functions for color and alpha, and this is achieved by using glBlendFuncSeparate :

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);

Does the blend func you want.

Just draw your opaque square, then check the alpha channel. If it's not showing up as fully white when a known-opaque square is rendered, you may have a problem with some other setting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM