flopoloco's picture

Red Alert Flashing Screen

/* 
 * Red Alert Example
 * by flopoloco
 * Description: Red flashing alert screen
 * 
 * */
 
using System;
using System.Drawing;
 
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using OpenTK.Platform;
 
namespace OpenTKExamples
{
	public class Game : GameWindow
	{
		private float colorIntensity = 0f;
		private bool alertState = true;
 
		public Game() : base(800, 600, GraphicsMode.Default, "Red Alert Example")
		{
		}
 
		public override void OnRenderFrame(RenderFrameEventArgs e)
		{		
			GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
			SwapBuffers();
		}
 
 
		public override void OnUpdateFrame(UpdateFrameEventArgs e)
		{
			if (Keyboard[Key.Escape])
                Exit();		
 
			if (this.alertState)
			{
				this.colorIntensity++;
				if (this.colorIntensity > 360)
					this.colorIntensity = 0;
			}
			else
			{
				if (this.colorIntensity > 0f)
					this.colorIntensity *= 0.8f;
			}
 
			GL.ClearColor((float)Math.Sin((double)this.colorIntensity), 0f, 0f, 1f);
		}
 
		[STAThread]
		private static void Main()
		{
			using (Game game = new Game())
			{
				game.Run(30.0, 0.0);
			}
		}
 
	}
}

Do any modifications freely:
TODO: Turn on/off the alarm (with keypress)
TODO: Play sound (needs OpenAL support)
TODO: Add VSYNC mode, tearing occurs.