コード例 #1
0
        protected override void InitializeService()
        {
            // \todo fix
            quadRenderer = new QuadRenderer(renderer);

            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            window.SwapBuffers();

            windowViewport = new Viewport(window.Width, window.Height);
            renderer.Requested.Viewport = windowViewport;

            camera2D      = new Camera();
            camera2D.Name = "camera2D";
            Update2DCamera();

            if (Configuration.voxelTest)
            {
                map.UpdateChunksAround(0, 0);
                map.UpdateRender();
            }

            timers = new Timers();

            InitializeCommonMaterials();
        }
コード例 #2
0
        public void Message(string message)
        {
            Begin();

            Rectangle bounds = new Rectangle();

            //TextBuffer.BeginPrint();
            TextBuffer.Print(0.0f, 10.0f, 0.0f, message, bounds);
            //TextBuffer.EndPrint();

            // NOTE: Using fractional coordinates would be a bad idea
            frame.LocalToParent.SetTranslation(
                (float)(int)(window.Width / 2 - bounds.Size.X / 2),
                (float)(int)(window.Height / 2 - bounds.Size.Y / 2),
                0.0f
                );

            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            for (int i = 0; i < 2; ++i)
            {
                GL.Clear(ClearBufferMask.ColorBufferBit);
                renderer.RenderCurrent();

                window.SwapBuffers();
            }

            End();
        }
コード例 #3
0
        public void Message(string message)
        {
            SetupRenderer();

            renderer.SetFrame(frame);

            TextBuffer.Print(0.0f, 10.0f, 0.0f, message);
            Rectangle bounds = TextBuffer.FontStyle.Bounds;

            // NOTE: Using fractional coordinates would be a bad idea
            frame.LocalToParent.SetTranslation(
                (float)(int)(window.Width / 2 - bounds.Size.X / 2),
                (float)(int)(window.Height / 2 - bounds.Size.Y / 2),
                0.0f
                );

            OpenTK.VSyncMode oldSync = window.VSync;
            window.VSync = OpenTK.VSyncMode.Off;
            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            for (int i = 0; i < 2; ++i)
            {
                GL.Clear(ClearBufferMask.ColorBufferBit);
                renderer.RenderCurrent();

                window.SwapBuffers();
            }
            window.VSync = oldSync;
        }
コード例 #4
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();
            }
        }