2007-09-02 00:07:40 +00:00
|
|
|
|
#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;
|
2007-09-02 13:34:44 +00:00
|
|
|
|
using System.Diagnostics;
|
2007-09-02 00:07:40 +00:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
2008-02-02 00:58:26 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
2008-03-08 14:38:10 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2008-02-02 00:58:26 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL.Enums;
|
2008-01-24 12:36:40 +00:00
|
|
|
|
using OpenTK.Input;
|
2007-09-02 00:07:40 +00:00
|
|
|
|
|
|
|
|
|
namespace Examples.Tutorial
|
|
|
|
|
{
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Demonstrates the GameWindow class.
|
|
|
|
|
/// </summary>
|
2007-11-11 18:44:10 +00:00
|
|
|
|
[Example("Simple Window", ExampleCategory.Tutorial, 1)]
|
|
|
|
|
public class T01_Simple_Window : GameWindow
|
2007-09-02 00:07:40 +00:00
|
|
|
|
{
|
2008-05-04 16:28:04 +00:00
|
|
|
|
public T01_Simple_Window() : base(800, 600)
|
2008-01-24 12:36:40 +00:00
|
|
|
|
{
|
|
|
|
|
Keyboard.KeyDown += new OpenTK.Input.KeyDownEvent(Keyboard_KeyDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Keyboard_KeyDown
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when a key is pressed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The KeyboardDevice which generated this event.</param>
|
|
|
|
|
/// <param name="key">The key that was pressed.</param>
|
|
|
|
|
void Keyboard_KeyDown(KeyboardDevice sender, Key key)
|
|
|
|
|
{
|
|
|
|
|
if (sender[Key.Escape])
|
|
|
|
|
this.Exit();
|
2008-05-04 14:45:33 +00:00
|
|
|
|
|
|
|
|
|
if ((sender[Key.AltLeft] || sender[Key.AltRight]) && (sender[Key.Enter] || sender[Key.KeypadEnter]))
|
|
|
|
|
if (this.WindowState == WindowState.Fullscreen)
|
|
|
|
|
this.WindowState = WindowState.Normal;
|
|
|
|
|
else
|
|
|
|
|
this.WindowState = WindowState.Fullscreen;
|
2008-01-24 12:36:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2007-10-26 15:55:07 +00:00
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
#region OnLoad
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2007-09-26 23:15:18 +00:00
|
|
|
|
/// Setup OpenGL and load resources here.
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">Not used.</param>
|
|
|
|
|
public override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
2009-02-12 23:42:11 +00:00
|
|
|
|
GL.ClearColor(Color.MidnightBlue);
|
2007-09-26 11:47:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-09-22 22:01:43 +00:00
|
|
|
|
#region OnResize
|
|
|
|
|
|
2007-09-22 15:07:28 +00:00
|
|
|
|
/// <summary>
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// Respond to resize events here.
|
2007-09-22 15:07:28 +00:00
|
|
|
|
/// </summary>
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// <param name="e">Contains information on the new GameWindow size.</param>
|
|
|
|
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
2007-09-22 15:07:28 +00:00
|
|
|
|
protected override void OnResize(OpenTK.Platform.ResizeEventArgs e)
|
|
|
|
|
{
|
2007-11-10 23:31:01 +00:00
|
|
|
|
GL.Viewport(0, 0, Width, Height);
|
2007-09-22 15:07:28 +00:00
|
|
|
|
|
2007-11-04 15:32:24 +00:00
|
|
|
|
GL.MatrixMode(MatrixMode.Projection);
|
2007-09-22 15:07:28 +00:00
|
|
|
|
GL.LoadIdentity();
|
|
|
|
|
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
|
|
|
|
|
|
|
|
|
|
base.OnResize(e);
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-22 22:01:43 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
#region OnUpdateFrame
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add your game logic here.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">Contains timing information.</param>
|
|
|
|
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
|
|
|
|
public override void OnUpdateFrame(UpdateFrameEventArgs e)
|
|
|
|
|
{
|
2008-01-24 12:36:40 +00:00
|
|
|
|
// Nothing to do!
|
2007-09-26 11:47:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2007-09-22 22:01:43 +00:00
|
|
|
|
#region OnRenderFrame
|
|
|
|
|
|
2007-09-02 00:07:40 +00:00
|
|
|
|
/// <summary>
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// Add your game rendering code here.
|
2007-09-02 00:07:40 +00:00
|
|
|
|
/// </summary>
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// <param name="e">Contains timing information.</param>
|
|
|
|
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
2007-09-23 12:09:42 +00:00
|
|
|
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
2007-09-02 00:07:40 +00:00
|
|
|
|
{
|
2007-11-04 15:32:24 +00:00
|
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
|
|
|
|
|
|
GL.Begin(BeginMode.Triangles);
|
2007-09-02 00:07:40 +00:00
|
|
|
|
|
2009-02-12 23:42:11 +00:00
|
|
|
|
GL.Color3(Color.MidnightBlue);
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Vertex2(-1.0f, 1.0f);
|
2007-11-10 23:31:01 +00:00
|
|
|
|
GL.Color3(Color.SpringGreen);
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Vertex2(0.0f, -1.0f);
|
2007-11-10 23:31:01 +00:00
|
|
|
|
GL.Color3(Color.Ivory);
|
2007-09-02 00:07:40 +00:00
|
|
|
|
GL.Vertex2(1.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
GL.End();
|
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
this.SwapBuffers();
|
2007-09-02 00:07:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-22 22:01:43 +00:00
|
|
|
|
#endregion
|
2007-11-11 18:44:10 +00:00
|
|
|
|
|
|
|
|
|
#region public static void Main()
|
2007-09-02 00:07:40 +00:00
|
|
|
|
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// <summary>
|
2007-11-11 18:44:10 +00:00
|
|
|
|
/// Entry point of this example.
|
2007-09-26 11:47:30 +00:00
|
|
|
|
/// </summary>
|
2007-11-11 18:44:10 +00:00
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main()
|
2007-09-02 00:07:40 +00:00
|
|
|
|
{
|
2007-11-11 18:44:10 +00:00
|
|
|
|
using (T01_Simple_Window example = new T01_Simple_Window())
|
|
|
|
|
{
|
|
|
|
|
// Get the title and category of this example using reflection.
|
2008-01-24 12:36:40 +00:00
|
|
|
|
Utilities.SetWindowTitle(example);
|
2007-11-11 18:44:10 +00:00
|
|
|
|
example.Run(30.0, 0.0);
|
|
|
|
|
}
|
2007-09-02 00:07:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|