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

Started by
3 comments, last by dpadam450 12 years, 1 month ago
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
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.
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);

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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
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.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement