2009-11-04 22:22:41 +01:00
|
|
|
// Released to the public domain. Use, modify and relicense at will.
|
|
|
|
|
2009-09-03 21:01:11 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
using OpenTK.Audio;
|
|
|
|
using OpenTK.Audio.OpenAL;
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
|
|
namespace StarterKit
|
|
|
|
{
|
|
|
|
class Game : GameWindow
|
|
|
|
{
|
|
|
|
/// <summary>Creates a 800x600 window with the specified title.</summary>
|
|
|
|
public Game()
|
|
|
|
: base(800, 600, GraphicsMode.Default, "OpenTK Quick Start Sample")
|
|
|
|
{
|
|
|
|
VSync = VSyncMode.On;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Load resources here.</summary>
|
|
|
|
/// <param name="e">Not used.</param>
|
2009-10-21 15:33:00 +02:00
|
|
|
protected override void OnLoad(EventArgs e)
|
2009-09-03 21:01:11 +02:00
|
|
|
{
|
2009-10-14 20:25:51 +02:00
|
|
|
base.OnLoad(e);
|
|
|
|
|
2009-11-04 22:22:41 +01:00
|
|
|
GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
|
2009-09-03 21:01:11 +02:00
|
|
|
GL.Enable(EnableCap.DepthTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when your window is resized. Set your viewport here. It is also
|
|
|
|
/// a good place to set up your projection matrix (which probably changes
|
|
|
|
/// along when the aspect ratio of your window).
|
|
|
|
/// </summary>
|
2009-10-14 20:25:51 +02:00
|
|
|
/// <param name="e">Not used.</param>
|
2009-09-03 21:01:11 +02:00
|
|
|
protected override void OnResize(EventArgs e)
|
|
|
|
{
|
2009-10-14 20:25:51 +02:00
|
|
|
base.OnResize(e);
|
|
|
|
|
2009-11-04 22:22:41 +01:00
|
|
|
GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
|
2009-09-03 21:01:11 +02:00
|
|
|
|
|
|
|
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 64.0f);
|
|
|
|
GL.MatrixMode(MatrixMode.Projection);
|
|
|
|
GL.LoadMatrix(ref projection);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when it is time to setup the next frame. Add you game logic here.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="e">Contains timing information for framerate independent logic.</param>
|
|
|
|
protected override void OnUpdateFrame(FrameEventArgs e)
|
|
|
|
{
|
2009-10-14 20:25:51 +02:00
|
|
|
base.OnUpdateFrame(e);
|
|
|
|
|
2009-09-03 21:01:11 +02:00
|
|
|
if (Keyboard[Key.Escape])
|
|
|
|
Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when it is time to render the next frame. Add your rendering code here.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="e">Contains timing information.</param>
|
|
|
|
protected override void OnRenderFrame(FrameEventArgs e)
|
|
|
|
{
|
2009-10-14 20:25:51 +02:00
|
|
|
base.OnRenderFrame(e);
|
|
|
|
|
2009-09-03 21:01:11 +02:00
|
|
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
|
|
|
|
|
|
|
Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
|
|
|
|
GL.MatrixMode(MatrixMode.Modelview);
|
|
|
|
GL.LoadMatrix(ref modelview);
|
|
|
|
|
|
|
|
GL.Begin(BeginMode.Triangles);
|
|
|
|
|
2009-11-04 22:22:41 +01:00
|
|
|
GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, 4.0f);
|
|
|
|
GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.0f, -1.0f, 4.0f);
|
|
|
|
GL.Color3(0.2f, 0.9f, 1.0f); GL.Vertex3(0.0f, 1.0f, 4.0f);
|
2009-09-03 21:01:11 +02:00
|
|
|
|
|
|
|
GL.End();
|
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The main entry point for the application.
|
|
|
|
/// </summary>
|
|
|
|
[STAThread]
|
|
|
|
static void Main()
|
|
|
|
{
|
|
|
|
// The 'using' idiom guarantees proper resource cleanup.
|
|
|
|
// We request 30 UpdateFrame events per second, and unlimited
|
|
|
|
// RenderFrame events (as fast as the computer can handle).
|
|
|
|
using (Game game = new Game())
|
|
|
|
{
|
|
|
|
game.Run(30.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-25 17:35:42 +02:00
|
|
|
}
|