PDA

View Full Version : Fade In / Out effect on 2D



Krimsom King
04-11-2012, 05:49 PM
Hi there,

I am trying to make a fade in & out effect on 2D elements I show on the screen, whether it's text I show or simply a 2D Quad with a texture on it.

Is there an easy trick to put an alpha value before showing the element and get something semi-transparent or invisible? Color blending?

Thanks.

BionicBytes
04-12-2012, 02:47 AM
Is there an easy trick to put an alpha value before showing the element and get something semi-transparent or invisible? Color blending?

Yes.
Enable blending and use GL_SOURCE_ALPHA,GL_ONE_MINUS_SOURCE_ALPHA for the blend equation.
Then just before you draw the UI element, use glColor4f (1,1,1, Alpha) where alpha is the transparency value between 0.0 -> 1.0.
if you are using a shader or GL 3.x core profile, then you'd need to send the alpha value in as a uniform instead.

Krimsom King
04-12-2012, 01:00 PM
Ha thanks!

Having worked a little bit with color functions, I was on the right track for this. That work.