using System; using System.Drawing; using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using OpenTK.Input; namespace OpenGL_110825 { class Program { public float rtri; // rtri is for rotating the pyramid public static double rquad = 30; // rquad is for rotating the quad [STAThread] public static void Main() { using (var game = new GameWindow()) { game.Load += (sender, e) => { // setup settings, load textures, sounds game.VSync = VSyncMode.On; GL.ShadeModel(ShadingModel.Smooth); GL.ClearColor(0, 0, 0, 0.5f); GL.ClearDepth(1); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); }; game.Resize += (sender, e) => { //GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); //Matrix4 m_prespective = Matrix4.Perspective((float) System.Math.PI / 4, game.Width / game.Height, 1, 100); Matrix4d m_prespective = Matrix4d.CreatePerspectiveFieldOfView(System.Math.Pi / 4, (float)game.Width / (float)game.Height, 1.0, 100); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref m_prespective); GL.Viewport(0, 0, game.Width, game.Height); }; game.UpdateFrame += (sender, e) => { // add game logic, input handling if (game.Keyboard[Key.Escape]) { game.Exit(); } }; game.RenderFrame += (sender, e) => { //GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0); // render graphics GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Translate(0.3, 1, -3); GL.Rotate(rquad, 1, 1, 1); rquad -= 0.05; GL.Begin(PrimitiveType.Polygon); GL.Color3(Color.Gray); GL.Vertex3(0.0f, 0.0f, 0.0f); // Top of Triangle (Front) GL.Vertex3(0.0f, 0.46f, 0.0f); GL.Vertex3(0.77f, 0.46f, 0.0f); GL.Vertex3(0.77f, 0.34f, 0.0f); GL.Vertex3(0.92f, 0.34f, 0.0f); GL.Vertex3(0.92f, 0.12f, 0.0f); GL.Vertex3(0.77f, 0.12f, 0.0f); GL.Vertex3(0.77f, 0.0f, 0.0f); GL.Color3(Color.Gray); GL.Vertex3(0.0f, 0.0f, 0.0f); GL.Vertex3(0.0f, 0.0f, 0.45f); GL.Vertex3(0.45f, 0.0f, 0.45f); GL.Vertex3(0.77f, 0.0f, 0.11f); GL.Vertex3(0.77f, 0.0f, 0.0f); GL.Color3(Color.Gray); GL.Vertex3(0.0f, 0.46f, 0.0f); GL.Vertex3(0.0f, 0.46f, 0.45f); GL.Vertex3(0.45f, 0.46f, 0.45f); GL.Vertex3(0.77f, 0.46f, 0.11f); GL.Vertex3(0.77f, 0.46f, 0.0f); GL.Color3(Color.Gray); GL.Vertex3(0.92f, 0.12f, 0.0f); GL.Vertex3(0.77f, 0.12f, 0.0f); GL.Vertex3(0.77f, 0.12f, 0.11f); GL.Vertex3(0.62f, 0.12f, 0.23f); GL.Vertex3(0.92f, 0.12f, 0.23f); GL.Color3(Color.Gray); GL.Vertex3(0.92f, 0.34f, 0.0f); GL.Vertex3(0.77f, 0.34f, 0.0f); GL.Vertex3(0.77f, 0.34f, 0.11f); GL.Vertex3(0.62f, 0.34f, 0.23f); GL.Vertex3(0.92f, 0.34f, 0.23f); GL.Color3(Color.Gray); GL.Vertex3(0.77f, 0.0f, 0.11f); GL.Vertex3(0.45f, 0.0f, 0.45f); GL.Vertex3(0.45f, 0.17f, 0.45f); GL.Vertex3(0.595f, 0.17f, 0.32f); GL.Vertex3(0.595f, 0.29f, 0.32f); GL.Vertex3(0.45f, 0.29f, 0.45f); GL.Vertex3(0.45f, 0.46f, 0.45f); GL.Vertex3(0.77f, 0.46f, 0.11f); GL.Vertex3(0.77f, 0.34f, 0.1f); GL.Vertex3(0.62f, 0.34f, 0.23f); GL.Vertex3(0.62f, 0.12f, 0.23f); GL.Vertex3(0.77f, 0.12f, 0.11f); GL.End(); game.SwapBuffers(); }; // Run the game at 60 updates per second game.Run(60.0); } } } }