using System using System Drawing using OpenTK using OpenTK Graphics u

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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);
}
}
}
}