mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-27 08:05:36 +00:00
6bbaad8bfb
Made example source code visible for all examples in example browser. Updated Prebuild.exe to newest SVN version (resolves issues with resources). Added .rtf and .resx files to Examples project in Prebuild.xml.
146 lines
4 KiB
C#
146 lines
4 KiB
C#
#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.Graphics.OpenGL;
|
|
using OpenTK.Graphics;
|
|
using OpenTK.Graphics.OpenGL.Enums;
|
|
using OpenTK.Input;
|
|
|
|
namespace Examples.Tutorial
|
|
{
|
|
/// <summary>
|
|
/// Demonstrates the GameWindow class.
|
|
/// </summary>
|
|
[Example("Simple Window", ExampleCategory.OpenTK, "GameWindow", Documentation="SimpleWindow")]
|
|
public class SimpleWindow : GameWindow
|
|
{
|
|
public SimpleWindow() : base(800, 600)
|
|
{
|
|
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();
|
|
|
|
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;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnLoad
|
|
|
|
/// <summary>
|
|
/// Setup OpenGL and load resources here.
|
|
/// </summary>
|
|
/// <param name="e">Not used.</param>
|
|
public override void OnLoad(EventArgs e)
|
|
{
|
|
GL.ClearColor(Color.MidnightBlue);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnResize
|
|
|
|
/// <summary>
|
|
/// Respond to resize events here.
|
|
/// </summary>
|
|
/// <param name="e">Contains information on the new GameWindow size.</param>
|
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
|
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
|
|
|
|
/// <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)
|
|
{
|
|
// Nothing to do!
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OnRenderFrame
|
|
|
|
/// <summary>
|
|
/// Add your game rendering code here.
|
|
/// </summary>
|
|
/// <param name="e">Contains timing information.</param>
|
|
/// <remarks>There is no need to call the base implementation.</remarks>
|
|
public override void OnRenderFrame(RenderFrameEventArgs e)
|
|
{
|
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
GL.Begin(BeginMode.Triangles);
|
|
|
|
GL.Color3(Color.MidnightBlue);
|
|
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()
|
|
|
|
/// <summary>
|
|
/// Entry point of this example.
|
|
/// </summary>
|
|
[STAThread]
|
|
public static void Main()
|
|
{
|
|
using (SimpleWindow example = new SimpleWindow())
|
|
{
|
|
// Get the title and category of this example using reflection.
|
|
Utilities.SetWindowTitle(example);
|
|
example.Run(30.0, 0.0);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|