コード例 #1
0
        public void BufferAntialiasing()
        {
            var window = new OpenTK.GameWindow(graphics.PreferredBackBufferWidth,
                                               graphics.PreferredBackBufferHeight, new OpenTK.Graphics.GraphicsMode(32, 0, 0, MultisampleCount));

            window.Exit();
            window.Dispose();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Relfos/LunarRaycaster
        static void Main(string[] args)
        {
            var timer = new Stopwatch();

            timer.Start();

            int bufferTexID = 0;

            int lastMouseX = -1;
            int lastMouseY = -1;

            float mouseDeltaX    = 0;
            float mouseDeltaY    = 0;
            float newMouseDeltaX = 0;
            float newMouseDeltaY = 0;

            engine = new CustomRaycaster();

            using (var game = new OpenTK.GameWindow(engine.Output.Width * scale, engine.Output.Height * scale, GraphicsMode.Default, "Raycasting"))
            {
                game.Load += (sender, e) =>
                {
                    // setup settings, load textures, sounds
                    game.VSync = OpenTK.VSyncMode.On;

                    bufferTexID = GL.GenTexture();
                    UpdateBuffer(bufferTexID);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                    game.Cursor = OpenTK.MouseCursor.Empty;
                };

                game.Resize += (sender, e) =>
                {
                    GL.Viewport(0, 0, game.Width, game.Height);
                };

                game.KeyDown += (sender, e) =>
                {
                    input.Add(e.Key);
                };

                game.KeyUp += (sender, e) =>
                {
                    input.Remove(e.Key);
                };

                game.MouseMove += (sender, e) =>
                {
                    if (lastMouseX != -1)
                    {
                        newMouseDeltaX = (lastMouseX - e.X) / (float)game.Width;
                        newMouseDeltaY = (lastMouseY - e.Y) / (float)game.Height;
                    }

                    lastMouseX = e.X;
                    lastMouseY = e.Y;
                };

                game.UpdateFrame += (sender, e) =>
                {
                    // add game logic, input handling
                    if (input.Contains(Key.Escape))
                    {
                        game.Exit();
                        Environment.Exit(0);
                    }

                    float speed = 0.02f;

                    if (input.Contains(Key.W))
                    {
                        engine.Camera.Move(speed);
                    }
                    if (input.Contains(Key.S))
                    {
                        engine.Camera.Move(-speed);
                    }
                    if (input.Contains(Key.A))
                    {
                        engine.Camera.Strafe(-speed);
                    }
                    if (input.Contains(Key.D))
                    {
                        engine.Camera.Strafe(speed);
                    }

                    if (input.Contains(Key.Left))
                    {
                        engine.Camera.Rotate(speed);
                    }
                    if (input.Contains(Key.Right))
                    {
                        engine.Camera.Rotate(-speed);
                    }

                    if (input.Contains(Key.Up))
                    {
                        engine.Camera.Look(speed);
                    }
                    if (input.Contains(Key.Down))
                    {
                        engine.Camera.Look(-speed);
                    }

                    mouseDeltaX = Mathf.Lerp(mouseDeltaX, newMouseDeltaX, 0.5f);
                    mouseDeltaY = Mathf.Lerp(mouseDeltaY, newMouseDeltaY, 0.5f);

                    engine.Camera.Rotate(mouseDeltaX * 32);
                    engine.Camera.Look(mouseDeltaY * 32);

                    newMouseDeltaX = 0;
                    newMouseDeltaY = 0;
                    if (game.Focused)
                    {
                        OpenTK.Input.Mouse.SetPosition(game.X + game.Width / 2, game.Y + game.Height / 2);
                    }
                };

                game.Closed += (sender, e) =>
                {
                    //shouldStop = true;
                };

                long lastTick = timer.ElapsedMilliseconds;

                game.RenderFrame += (sender, e) =>
                {
                    engine.Render();

                    UpdateBuffer(bufferTexID);
                    DrawBuffer(game, bufferTexID);

                    game.SwapBuffers();

                    lastTick = timer.ElapsedMilliseconds;
                };

                game.Run();
            }
        }