Jump to content
  • Advertisement
Sign in to follow this  
floatingwoods

Fading a texture with alpha channel (i.e. "double transparency")

This topic is 2481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

EDIT: I need to fade a texture and a bitmap (text).

Hello,

I have a texture (with alpha channel) that I render using the usual function:

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

That works fine. Now I wish to additionally weight the texture with a value between 0 and 1 (the "FADE_FACTOR"),

where 0 means: no texture is visible, the destination colors are unmodified
and 1 means: the texture is visible in the usual way (normal operation of above blending function).

This will allow me to gradually fade the texture in and out. How can I achieve that?

Ideally, I would need something like:

glBlendFunc(SOURCE_ALPHA * FADE_FACTOR,1 - (SOURCE_ALPHA * FADE_FACTOR));

Thanks for any insight

Share this post


Link to post
Share on other sites
Advertisement
Easily done with a shader. Pass in a uniform or vertex attribute for your display factor. Multiply the alpha component of the sampled texture color by this factor. Write result (possibly discarding fully transparent pixels of you don't want z-writes on transparency) to the fragment color.

Sorry for not posting sample code; using my phone to type this and typing code on this thing is not pleasant. However, this is basically a trivial two line change to the simplest textured fragment shader.

Share this post


Link to post
Share on other sites
glColor4f() works with alpha textures, just call that with your alpha parameter being your fade value.

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(x,x,x, fade_value);

Share this post


Link to post
Share on other sites
Thanks elanthis and dpadam450!

I would prefer not using any shader for that (since I don't have any experience with that and otherwise no direct use). The glColor4f function does the trick, but it seems that it doesn't have any effect on my text (which are bitmaps). I guess that is a limitation of bitmaps...

Cheers

Share this post


Link to post
Share on other sites
I guess that is a limitation of bitmaps...[/quote]
You are doing something wrong. Graphics cards don' see bitmaps and jpegs, they see RGB, RGBA. You may have some other code running with your bitmaps. You must also turn on blending when drawing bitmaps as well, since you intend to use alpha now and blend them with the background.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!