Skip to main content
gamedev.net
🔒 Locked

Fade Out

Started by gellin May 27, 2006 at 1:04 PM 2 replies 850+ views
Original Post
gellin
gellin
I want to do a fade out effect but I haven't used OpenGL in over 2 months and can't remember the details on how I would do it. I want to either: A) Place a quad over the entire screen and adjust it's alpha values over time or B) Play around with the light so that it fades from on to off over time. If anyone can give me details on how to do one of these or if there is an even easier way, it would be greatly appreciated. Thanks Edit: I already know how to do the over time stuff, I just need to know how to adjust the quad or light.
nts
nts
For the quad approach you simply need to draw an alpha blended black quad over the screen with the fade as the alpha color (0 to 255, 0.0 - 1.0f, etc).

Basically like the following
// enable alpha blendingglEnable(GL_BLEND); // blending function you want (I think this will work)glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // set the color (black) and alpha valueglColor4u(0, 0, 0, alpha_value); // draw the quad, where 'w' and 'h' are your viewport/window sizesglBegin(GL_QUADS);	glVertex2i(0, 0);	glVertex2i(w, 0);	glVertex2i(w, h);	glVertex2i(0, h);glEnd(); // done, disabled blendingglDisable(GL_BLEND);


Hope that helps
mmelson
mmelson
Also, don't forget that you'll probably want to disable the z-buffer when you render the quad (though, depending on your exact setup, it might not be necessary).
gellin
gellin
Thanks for the help nts. I had actually tried that but it didn't work for me before (glad I didn't forget everything about this stuff). Anyways I got it working. It turns out I had to play around with the BlendFunc and came up with this:

glBlendFunc( GL_SRC_ALPHA, GL_SRC_ALPHA);

I also had to disable lighting before I drew this quad but other than that your code was spot on.

Thanks guys.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.