Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gekko513

macrumors 603
Original poster
Oct 16, 2003
6,301
1
I probably wouldn't really strangle them, but the default available OpenGL blending functions miss the most useful, logical and natural blending option. I'm talking about the regular source-over blending as you can find in PhotoShop and basically anywhere. This is so infuriating!

Here's what I want to do. I want to render a rectangular background with transparent edges. On top of that background i want to render an antialiased button with a soft black drop shadow.

OpenGL seems to recommend the blending function:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for drawing on top of an existing buffer.

So what does this function do if I use this fucntion and render the background, then render the drop shadow and finally render the button?

The result is a buffer that is slightly transparent where the drop shadow and the antialiased edges of the button is. This is not acceptable, as this makes other windows shine through in the application I'm building.

Another option is:
glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);

This function only draws in transparent areas of the buffer, so I draw the button first, then the drop shadow and finally the background. The result is almost what I want, except that in areas where I render two transparent layers, the resulting opacity is additive and not multiplicative, so the antialiased edge around the button combined with the drop shadow creates an almost pitch black edge, which isn't what I wanted, not what it would look like in PhotoShop and it looks terrible.

Anyone have a suggestion? Probably not many developers using OpenGL here, but it's worth a shot. Also helps me vent.

Some documention for the glBlendFunc can be found here link
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.