3.立方体和旋转

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();
  
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值