Пример #1
0
        public override void Render(float time, float deltaTime)
        {
            _shaderProgram.SetUniform("projection", ref Window.ProjectionMatrix);

            RenderContext.Clear(_backgroundColor);

            _spriteBatch.Begin(_shaderProgram);

            _spriteBatch.DrawString(_roboto, _str, new Vector2(100, 100), _textColor, _scale);

            _spriteBatch.End();

            ImGui.Begin("Font--");

            ImGui.InputInt("Height", ref _height);
            ImGui.InputText("Display String", ref _str, 128);
            ImGui.DragFloat("Text Scale", ref _scale);

            ImGui.Separator();

            ImGuiHelper.ColorEdit4("Text Color", ref _textColor);
            ImGuiHelper.ColorEdit4("Background Color", ref _backgroundColor);

            ImGui.Separator();

            if (ImGui.Button("Reload"))
            {
                ImGuiHelper.UnbindTexture(_textureHandle);
                _roboto.Dispose();
                _roboto        = new Font(RenderContext, "./Assets/Fonts/Roboto-Medium.ttf", (uint)_height);
                _textureHandle = ImGuiHelper.BindTexture(_roboto.FontAtlas);
            }

            ImGui.Separator();
            ImGuiHelper.Image(_textureHandle, new Vector2(_roboto.FontAtlas.Width, _roboto.FontAtlas.Height));

            ImGui.End();

            ImGui.ShowMetricsWindow();
        }
Пример #2
0
        public override void Render(float time, float deltaTime)
        {
            _viewMatrix       = Matrix4x4.CreateLookAt(_cameraPosition, _cameraTarget, Vector3Helper.Up);
            _modelMatrix      = Matrix4x4.CreateRotationY(0f * 3f);
            _projectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView(1.0f, Window.AspectRatio, 0.1f, 10_000.0f);

            _shader.SetUniform("model", ref _modelMatrix);
            _shader.SetUniform("view", ref _viewMatrix);
            _shader.SetUniform("projection", ref _projectionMatrix);

            _shader.TrySetUniform("lightPos", _lightPos);
            _shader.TrySetUniform("lightColor", _lightColor.ToVector3());
            _shader.TrySetUniform("cameraPos", _cameraPosition);

            RenderContext.Clear(Color.Black);

            if (_skybox0 != null)
            {
                var viewMatrixNoTranslation = _viewMatrix;
                viewMatrixNoTranslation.Translation = Vector3.Zero;

                _skyboxShader.SetUniform("view", ref viewMatrixNoTranslation);
                _skyboxShader.SetUniform("projection", ref _projectionMatrix);
                _skyboxShader.SetUniform("skybox", 0);

                _skybox0.Bind(0, RenderContext);
                RenderContext.DepthMask = false;
                _skyboxMesh.Render(RenderContext, _skyboxShader);
                RenderContext.DepthMask = true;
            }

            if (_nanosuit != null)
            {
                RenderContext.Render(_nanosuit, _shader);
            }

            _shader.SetUniform("model", Matrix4x4.CreateTranslation(_lightPos));

            _mesh.Render(RenderContext, _shader);

            ImGuiHelper.BeginGlobalDocking(false);
            ImGui.End();

            ImGui.Begin("Controls");
            {
                ImGui.DragFloat3("Camera Position", ref _cameraPosition);
                ImGui.DragFloat3("Camera Target", ref _cameraTarget);

                ImGui.Separator();

                ImGuiHelper.ColorEdit4("Light Color", ref _lightColor);
                ImGui.DragFloat3("Light Position", ref _lightPos);
            }
            ImGui.End();

            if (ImGui.Button("Quit"))
            {
                Quit();
            }

            ImGui.Separator();

            if (Window.VSync == VSyncMode.On)
            {
                if (ImGui.Button("Disable VSync"))
                {
                    Window.VSync = VSyncMode.Off;
                    _log.Info("VSync disabled.");
                }
            }
            else
            {
                if (ImGui.Button("Enable VSync"))
                {
                    Window.VSync = VSyncMode.On;
                    _log.Info("VSync enabled.");
                }
            }

            if (ImGui.Button("Set Fullscreen"))
            {
                Window.FullscreenState = FullscreenState.Fullscreen;
            }

            if (ImGui.Button("Set Windowed"))
            {
                Window.FullscreenState = FullscreenState.Windowed;
            }

            ImGui.End();

            ImGui.ShowMetricsWindow();
        }