Archived

This topic is now archived and is closed to further replies.

iScreaM

How can my sprite fade in?

Recommended Posts

I''d like to make my sprite(2D texture) fade to the background. But the sprite was irregular shaped,so i use a mask pic.first blend mask pic(GL_DST_COLOR, GL_ZERO),to make the pixel black where we should draw sprite on the background , then blend the sprite pic (GL_ONE, GL_ONE).it really works to draw the sprite on the background, but how to fade in it? The problem is in fact that i want the margin of the sprite pic to be transparent constantly, and pixels of the sprite to be transparent,semi-transparent,finally fade to be opaque.

Share this post


Link to post
Share on other sites
You''ll need to use a combination of alpha testing and alpha blending. You''ll alpha test out any pixels with an alpha of 0 or so, and then the rest of the image can be blended with the background using normal alpha rontines.

"Life is a double edged sword, we always hope to strike though adversity with the shining side..."

jkettles16 of Venosoft

Share this post


Link to post
Share on other sites
thx, but what do you mean with normal alpha routine? I want to increase the alpha value in every frame, to animate the sprite fading to the background.
tell me how?
thnx ag!

Share this post


Link to post
Share on other sites
You might want to draw the sprite as a texture onto a quad, and change the alpha value of that quad as a whole.


glBind(spriteTexture); // be sure that the sprite texture has alpha values as well (i.e RRGGBBAA)


while(alpha++ < fade_in_factor)
{
glColor4f(1, 1, 1, alpha); // Use the alpha value here to fade in


DrawSpriteAsQuad();
}

Share this post


Link to post
Share on other sites