From f285573885da28f9ee6867a80ec60891b7b84bc7 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 25 Aug 2009 15:35:42 +0000 Subject: [PATCH] Added QuickStart project. --- Source/QuickStart/Game.cs | 93 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Source/QuickStart/Game.cs diff --git a/Source/QuickStart/Game.cs b/Source/QuickStart/Game.cs new file mode 100644 index 00000000..77ee216c --- /dev/null +++ b/Source/QuickStart/Game.cs @@ -0,0 +1,93 @@ +using System; +using System.Drawing; + +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; +using OpenTK.Audio; +using OpenTK.Audio.OpenAL; +using OpenTK.Input; + +namespace StarterKit +{ + class Game : GameWindow + { + /// Creates a 800x600 window with the specified title. + public Game() + : base(800, 600, GraphicsMode.Default, "OpenTK Quick Start Sample") + { + VSync = VSyncMode.On; + } + + /// Load resources here. + /// Not used. + public override void OnLoad(EventArgs e) + { + GL.ClearColor(System.Drawing.Color.MidnightBlue); + GL.Enable(EnableCap.DepthTest); + } + + /// + /// 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). + /// + /// Contains information on the new Width and Size of the GameWindow. + protected override void OnResize(EventArgs e) + { + GL.Viewport(ClientRectangle); + + Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 64.0f); + GL.MatrixMode(MatrixMode.Projection); + GL.LoadMatrix(ref projection); + } + + /// + /// Called when it is time to setup the next frame. Add you game logic here. + /// + /// Contains timing information for framerate independent logic. + protected override void OnUpdateFrame(FrameEventArgs e) + { + if (Keyboard[Key.Escape]) + Exit(); + } + + /// + /// Called when it is time to render the next frame. Add your rendering code here. + /// + /// Contains timing information. + protected override void OnRenderFrame(FrameEventArgs e) + { + 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); + + GL.Color3(Color.Yellow); GL.Vertex3(-1.0f, -1.0f, 4.0f); + GL.Color3(Color.Red); GL.Vertex3(1.0f, -1.0f, 4.0f); + GL.Color3(Color.LightCyan); GL.Vertex3(0.0f, 1.0f, 4.0f); + + GL.End(); + + SwapBuffers(); + } + + /// + /// The main entry point for the application. + /// + [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); + } + } + } +} \ No newline at end of file