#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using OpenTK;
using OpenTK.OpenGL;
using OpenTK.Fonts;
using OpenTK.OpenGL.Enums;
namespace Examples.Tutorial
{
///
/// Demonstrates the GameWindow class.
///
[Example("Simple Window", ExampleCategory.Tutorial, 1)]
public class T01_Simple_Window : GameWindow
{
public T01_Simple_Window() : base(new DisplayMode(800, 600))
{ }
#region OnLoad
///
/// Setup OpenGL and load resources here.
///
/// Not used.
public override void OnLoad(EventArgs e)
{
GL.ClearColor(Color.SteelBlue);
}
#endregion
#region OnResize
///
/// Respond to resize events here.
///
/// Contains information on the new GameWindow size.
/// There is no need to call the base implementation.
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
{
GL.Viewport(0, 0, Width, Height);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
base.OnResize(e);
}
#endregion
#region OnUpdateFrame
///
/// Add your game logic here.
///
/// Contains timing information.
/// There is no need to call the base implementation.
public override void OnUpdateFrame(UpdateFrameEventArgs e)
{
base.OnUpdateFrame(e);
if (Keyboard[OpenTK.Input.Key.Escape])
this.Exit();
}
#endregion
#region OnRenderFrame
///
/// Add your game rendering code here.
///
/// Contains timing information.
/// There is no need to call the base implementation.
public override void OnRenderFrame(RenderFrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Begin(BeginMode.Triangles);
GL.Color3(Color.LightSteelBlue);
GL.Vertex2(-1.0f, 1.0f);
GL.Color3(Color.SpringGreen);
GL.Vertex2(0.0f, -1.0f);
GL.Color3(Color.Ivory);
GL.Vertex2(1.0f, 1.0f);
GL.End();
this.SwapBuffers();
}
#endregion
#region public static void Main()
///
/// Entry point of this example.
///
[STAThread]
public static void Main()
{
using (T01_Simple_Window example = new T01_Simple_Window())
{
// Get the title and category of this example using reflection.
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
example.Run(30.0, 0.0);
}
}
#endregion
}
}