private static void UpdateBackground(double TimeElapsed)
{
if (Game.CurrentInterface != Game.InterfaceType.Normal)
{
//Don't update the transition whilst paused
TimeElapsed = 0.0;
}
const float scale = 0.5f;
// fog
const float fogdistance = 600.0f;
if (Game.CurrentFog.Start < Game.CurrentFog.End & Game.CurrentFog.Start < fogdistance)
{
float cr = inv255 * (float)Game.CurrentFog.Color.R;
float cg = inv255 * (float)Game.CurrentFog.Color.G;
float cb = inv255 * (float)Game.CurrentFog.Color.B;
if (!FogEnabled)
{
GL.Fog(FogParameter.FogMode, (int)FogMode.Linear);
}
float ratio = (float)World.BackgroundImageDistance / fogdistance;
GL.Fog(FogParameter.FogStart, Game.CurrentFog.Start * ratio * scale);
GL.Fog(FogParameter.FogEnd, Game.CurrentFog.End * ratio * scale);
GL.Fog(FogParameter.FogColor, new float[] { cr, cg, cb, 1.0f });
if (!FogEnabled)
{
GL.Enable(EnableCap.Fog); FogEnabled = true;
}
}
else if (FogEnabled)
{
GL.Disable(EnableCap.Fog); FogEnabled = false;
}
//Update the currently displayed background
BackgroundManager.CurrentBackground.UpdateBackground(TimeElapsed, false);
if (BackgroundManager.TargetBackground == null || BackgroundManager.TargetBackground == BackgroundManager.CurrentBackground)
{
//No target background, so call the render function
BackgroundManager.CurrentBackground.RenderBackground(scale);
return;
}
//Update the target background
BackgroundManager.TargetBackground.UpdateBackground(TimeElapsed, true);
switch (BackgroundManager.TargetBackground.Mode)
{
//Render, switching on the transition mode
case BackgroundManager.BackgroundTransitionMode.FadeIn:
BackgroundManager.CurrentBackground.RenderBackground(1.0f, scale);
Renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);
BackgroundManager.TargetBackground.RenderBackground(BackgroundManager.TargetBackground.Alpha, scale);
break;
case BackgroundManager.BackgroundTransitionMode.FadeOut:
BackgroundManager.TargetBackground.RenderBackground(1.0f, scale);
Renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);
BackgroundManager.CurrentBackground.RenderBackground(BackgroundManager.TargetBackground.Alpha, scale);
break;
}
//If our target alpha is greater than or equal to 1.0f, the background is fully displayed
if (BackgroundManager.TargetBackground.Alpha >= 1.0f)
{
//Set the current background to the target & reset target to null
BackgroundManager.CurrentBackground = BackgroundManager.TargetBackground;
BackgroundManager.TargetBackground = null;
}
}