🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

problems with glBlendFunc

Started by
0 comments, last by Shadow Wolf 17 years, 2 months ago
Hi. Any help here would be greatly appreciated. I'm using a glOrtho view to draw a number of 2D sprites to the screen. What I want is that any sprites near the edges of the screen are faded to completely transparent from 100% opacity to 0% over a distance of 50 pixels. The sprites are rotated so I don't really want to calculate a bunch of smaller polygons and set the colors of each vertex appropriately. So my solution was to do the following: 1. Draw the background image with all alpha values set to 1.0 2. Set the blending mode to: glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO); 3. Draw a quad on the left edge of the screen (width=50, height=screenheight) the quad is a gradient that uses the colors: glColor4f(0.0f, 0.0f, 0.0f, 1.0f); for the right edge and glColor4f(0.0f, 0.0f, 0.0f, 0.0f); for the left edge 4. This should write only alpha values to the background image making an invisible alpha gradient in that rect 5. Set the blending func/equation to ???????????? 6. Draw my sprites all over the screen, some of which will intersect the gradient rect on the left edge and hopefully the pixels that make up the sprites will fade to the background image the closer they get to the left edge So my problem is step 5. I've tried setting the blend mode to: glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); but, while it does fade my sprites, it ignores the alpha channels of my sprites so all nice feathered edges and holes in the sprite are filled in to 100% opacity before being faded. Can anyone help me figure out the right combination of glBlendFunc/glBlendFuncSeparate/glBlendEquation/glBlendEquationSeparate I'm supposed to be using? Thanks!
Advertisement
Try glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), and be sure to enable alpha testing and color blending: glEnable(GL_ALPHA_TEST), glEnable(GL_BLEND).

This topic is closed to new replies.

Advertisement