Sign in to follow this  
KaelisAsur

glBlendFunc - fading frame buffer to color

Recommended Posts

I want to fade what i already have accumulated in my frame buffer to specific color. For starters, simple fade to black. So each frame i draw a quad big enough to fill the screen, with glColor4f(0.0f,0.0f,0.0f, fade ), where fade is set to a low value (0.001, for example), and i do not clear the frame buffer. My understanding is that the blending is performed with the following formula: result = sfactor * source + dfactor * destination Where source is pixel RGB value of incoming data, destination is pixel RGB value of data present in framebuffer and sfactor and dfactor are defined in glBlendFunc( GLenum sfactor, GLenum dfactor ). Since what i really want is to just reduce all pixel RGB values to 0, i thought i could just set glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA), which would give me 0 * source + 0.999 * destination (i know the fading process would actually 'slow down' with such setting, but nevermind that for now). Well, it doesnt work. The whole screen becomes black immediately. However, it kind of works with glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA). Kind of, because for pixel of RGB 255,255,255, for some odd reason it stops at 63,63,63. This confuses me even more. Why would GL_ONE matter, since the RGB values of source are all 0 anyway? And why does it stop at 63,63,63? Thanks.

Share this post


Link to post
Share on other sites
Have you enabled blending (GL_BLEND) and disabled alpha testing (GL_ALPHA_TESTING) before drawing your quad? Also, is it drawn after all the other graphics has been drawn?

Share this post


Link to post
Share on other sites
Yes, blending is enabled, alpha testing is disabled, and the quad is drawn after all the other graphics.

Here are my init settings:



glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDisable(GL_ALPHA_TEST);


Share this post


Link to post
Share on other sites
You need to use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Also, make sure to clear then screen and render the frame every time.

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
You need to use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Same results as glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)

Quote:
Also, make sure to clear then screen and render the frame every time.

But the whole point is to gradually fade the frame buffer each frame. So i need to keep the buffer, at least until it has faded out. If that wasnt the case, i would render a quad with varying transparency or just render everything to a texture beforehand and then fade the texture. But thats not what i want to do.

Share this post


Link to post
Share on other sites
try

<BLEND src="GL_CONSTANT_COLOR" dst="GL_ONE_MINUS_CONSTANT_COLOR"/>
glBlendColor( X,X,X,X );

though it mightnt completely clear the screen (like with what youre seeing)

Share this post


Link to post
Share on other sites
Quote:
Original post by KaelisAsur
But the whole point is to gradually fade the frame buffer each frame. So i need to keep the buffer, at least until it has faded out. If that wasnt the case, i would render a quad with varying transparency or just render everything to a texture beforehand and then fade the texture. But thats not what i want to do.


Typically, the back buffer is not preserved when you do a swapbuffer
We call that undefined behavior. On some GPU/drivers it works and on others it does not.
Anyway, you won't get any benefit by avoiding the re-render.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this