static void Main(string[] args)
{
GameWindow game = new GameWindow();
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
game.VSync = VSyncMode.On;
GL.ClearColor(System.Drawing.Color.MidnightBlue);
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.Viewport(0, 0, game.Width, game.Height);
//GL.Viewport(this.ClientRectangle);
GL.MatrixMode(MatrixMode.Projection);
Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, game.ClientRectangle.Width / (float)game.ClientRectangle.Height, 1.0F, 100F);
GL.LoadMatrix(ref proj);
};
game.Resize += (sender, e) =>
{
GL.Viewport(0, 0, game.Width, game.Height);
//GL.Viewport(this.ClientRectangle);
GL.MatrixMode(MatrixMode.Projection);
Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, game.ClientRectangle.Width / (float)game.ClientRectangle.Height, 1.0F, 100F);
GL.LoadMatrix(ref proj);
};
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
if (game.Keyboard[Key.Escape])
{
game.Exit();
}
if (game.Keyboard[Key.Enter])
{
if (game.WindowState == WindowState.Fullscreen)
{
game.WindowState = WindowState.Normal;
}
else
{
game.WindowState = WindowState.Fullscreen;
}
}
};
game.RenderFrame += (sender, e) =>
{
GL.ClearColor(Color.SkyBlue);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 modelView = Matrix4.LookAt(new Vector3(0.0F, 5.0F, 10.0F), Vector3.Zero, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelView);
//
GL.Rotate(_angle * 0.18F / (float)Math.PI, Vector3.One);
GL.Color4(Color.FromArgb(100, Color.Red));
GL.Begin(BeginMode.Triangles);
int i = 0;
foreach (var index in _cube.Indices)
{
switch (i%6)
{
case 0:
GL.Color3(Color.MidnightBlue);
break;
case 1:
GL.Color3(Color.SpringGreen);
break;
case 2:
GL.Color3(Color.YellowGreen);
break;
case 3:
GL.Color3(Color.YellowGreen);
break;
case 4:
GL.Color3(Color.SpringGreen);
break;
case 5:
GL.Color3(Color.OrangeRed);
break;
default:
GL.Color3(Color.Ivory);
break;
}
i++;
GL.Vertex3(_cube.Vertices[index]);
}
GL.End();
//
_angle++;
game.SwapBuffers();
};
game.Run();
}
3.立方体和旋转
最新推荐文章于 2024-07-28 13:19:43 发布