View Full Version : blending problem

04-17-2004, 12:03 AM
hi all, I want to produce the sun effect. however, i don't know if my blending setting is wrong, even I have been the "circle" texture, the blending still have some prblem

//first blending: for the outermost layer of sun
glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA ); glBindTexture(GL_TEXTURE_2D,g_Texture[NEBULA_ID]);
float sun_flare_size = 700;

//second blending: for the innermost layer of sun
sun_flare_size = 50;
glColor4f(1,.5f,0, 0.3);

After doing the above code, the effect is like:
this (http://www.csis.hku.hk/~pytang/blend.JPG)

Would anyone kindly point out my mistakes? Thanks

04-17-2004, 03:48 PM
Make sure you understand how the blending equation works, and how it applies to your image.

With BlendFunc( s, d ), you have:
blendResult = s * sourceColor + d * destinationColor, where sourceColor is the incoming fragment, and destinationColor is the color in the frame buffer.

Now, if you know how the alpha in your image varies, the rest should be easy. You blended with alpha in your code snippet, so I assume that your sun image has an alpha component. Let's say the alpha falls off radially from the center of the image. In this case, you might use
BlendFunc( SRC_ALPHA, ONE_MINUS_SRC_ALPHA ). This would scale the sun's contribution to the scene by the alpha value at the same location, and let (ONE_MINUS_SRC_ALPHA * frame buffer value) to show through from behind.

I hope this helps.