So I've got my particle system up and running and it looks great开发者_开发百科 as long as the background is dark. My problem is that I need to render the effect on light colored backgrounds to. I've been trying lots of different settings to glBlendFunc but can't figure out how to get it working. My current blending is glBlendFunc(GL_SRC_ALPHA, GL_ONE) and you can se the not so satisfying result in the image below. How do I render the effect on light colored backgrounds?
(source: babelstudios.se)If you have a normal ol' texture with alpha, and you're rendering in back-to-front order, this is the way to go:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
If your texture has premultiplied alpha, and you're rendering in back-to-front order, do this instead:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
From opengl.org
You might want to use the alpha values that result from texture mapping in the blend function. If so, (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) is always a good function to start with.
However, if you want blending to occur when the primitive is texture mapped (i.e., you want parts of the texture map to allow the underlying color of the primitive to show through), then don't use OpenGL blending. Instead, you'd use glTexEnv(), and set the texture environment mode to GL_BLEND. In this case, you'd want to leave the texture environment color to its default value of (0,0,0,0).
精彩评论