This project is read-only.

Scene fade to black

May 31, 2014 at 6:39 PM
It seems that this should be trivial but I am not having any luck with this. I have a SharpGL.SceneGraph.OpenGLCtrl with various objects in it. I would like a cinematic "fade to black" but changing the lighting gradually does not give me a gradual fade but instead will all of a sudden go from visible to black with nothing in between.
My current attempt is to change the color of each light in the scene gradually from white to black with a ctrl.Invalidate and a Thread.Sleep at each step.
Jun 23, 2014 at 5:34 AM
One thing you can do is use a blend function and compare the source alpha to 1-SrcAlpha...then place a polygon over the entire screen and set its color to black with a transparent alpha, then gradually step the alpha up to opaque...

A rough idea below. Obviously, you wouldn't normally define all the variables like this, but I hope it helps you follow what the different changes could make...
I also like to do this so that if I want to make a change, I can just find the variable section and modify the variable without having to search through code.


#region Fading Variables
bool FadeToBlack = false;   //controls incrementing ALPHA at render
float ALPHA = 0f;                //stores current alpha value - set to 0 for fully transparent
float ALPHA_STEP = 0.1f;     //larger values will fade faster)
float ALPHA_MAX = 1.0f;     //Used to know max alpha - when to stop incrementing - determined by ALPHA and RGB variable types
//changing the values below will fade to a different color - use R=1, G=1, B=1 for fading to white or R=1, G=0, B=1 for a Magenta
float FADE_R = 0.0f;
float FADE_G = 0.0f;
fload FADE_B = 0.0f;

Initialization code

Set up OpenGL to handle the blending...


//if true and ALPHA is below max value (0.0f-1.0f as a float/double, 0-255 as a byte/int)
if(FadeToBlack && ALPHA < ALPHA_MAX) {
[draw your rectangle]
I hope this helps you get an idea that you can use. Good luck.