ronag
ronag

Reputation: 51255

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?

Upvotes: 1

Views: 2428

Answers (2)

Dr. Snoopy
Dr. Snoopy

Reputation: 56357

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.

Upvotes: 7

ssube
ssube

Reputation: 48267

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.

Upvotes: -1

Related Questions