Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
// Released to the public domain. Use, modify and relicense at will.
2
 
3
using System;
4
 
5
using OpenTK;
6
using OpenTK.Graphics;
7
using OpenTK.Graphics.OpenGL;
8
using OpenTK.Audio;
9
using OpenTK.Audio.OpenAL;
10
using OpenTK.Input;
11
 
12
namespace StarterKit
13
{
14
    class Game : GameWindow
15
    {
16
        /// <summary>Creates a 800x600 window with the specified title.</summary>
17
        public Game()
18
            : base(800, 600, GraphicsMode.Default, "OpenTK Quick Start Sample")
19
        {
20
            VSync = VSyncMode.On;
21
        }
22
 
23
        /// <summary>Load resources here.</summary>
24
        /// <param name="e">Not used.</param>
25
        protected override void OnLoad(EventArgs e)
26
        {
27
            base.OnLoad(e);
28
 
29
            GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
30
            GL.Enable(EnableCap.DepthTest);
31
        }
32
 
33
        /// <summary>
34
        /// Called when your window is resized. Set your viewport here. It is also
35
        /// a good place to set up your projection matrix (which probably changes
36
        /// along when the aspect ratio of your window).
37
        /// </summary>
38
        /// <param name="e">Not used.</param>
39
        protected override void OnResize(EventArgs e)
40
        {
41
            base.OnResize(e);
42
 
43
            GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
44
 
45
            Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 64.0f);
46
            GL.MatrixMode(MatrixMode.Projection);
47
            GL.LoadMatrix(ref projection);
48
        }
49
 
50
        /// <summary>
51
        /// Called when it is time to setup the next frame. Add you game logic here.
52
        /// </summary>
53
        /// <param name="e">Contains timing information for framerate independent logic.</param>
54
        protected override void OnUpdateFrame(FrameEventArgs e)
55
        {
56
            base.OnUpdateFrame(e);
57
 
58
            if (Keyboard[Key.Escape])
59
                Exit();
60
        }
61
 
62
        /// <summary>
63
        /// Called when it is time to render the next frame. Add your rendering code here.
64
        /// </summary>
65
        /// <param name="e">Contains timing information.</param>
66
        protected override void OnRenderFrame(FrameEventArgs e)
67
        {
68
            base.OnRenderFrame(e);
69
 
70
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
71
 
72
            Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
73
            GL.MatrixMode(MatrixMode.Modelview);
74
            GL.LoadMatrix(ref modelview);
75
 
76
            GL.Begin(BeginMode.Triangles);
77
 
78
            GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, 4.0f);
79
            GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.0f, -1.0f, 4.0f);
80
            GL.Color3(0.2f, 0.9f, 1.0f); GL.Vertex3(0.0f, 1.0f, 4.0f);
81
 
82
            GL.End();
83
 
84
            SwapBuffers();
85
        }
86
 
87
        /// <summary>
88
        /// The main entry point for the application.
89
        /// </summary>
90
        [STAThread]
91
        static void Main()
92
        {
93
            // The 'using' idiom guarantees proper resource cleanup.
94
            // We request 30 UpdateFrame events per second, and unlimited
95
            // RenderFrame events (as fast as the computer can handle).
96
            using (Game game = new Game())
97
            {
98
                game.Run(30.0);
99
            }
100
        }
101
    }
102
}