From 9f3d9b33416bc007cf747b987d19af3705220017 Mon Sep 17 00:00:00 2001 From: 4sval Date: Sun, 28 Aug 2022 18:15:15 +0200 Subject: [PATCH] hello imgui --- FModel/FModel.csproj | 1 + FModel/Views/Snooper/Snooper.cs | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index c226e803..9b6e0217 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -131,6 +131,7 @@ + diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 14e5dc90..6a932aac 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -8,6 +8,7 @@ using Silk.NET.Input; using Silk.NET.Maths; using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; namespace FModel.Views.Snooper; @@ -15,6 +16,8 @@ namespace FModel.Views.Snooper; public class Snooper { private IWindow _window; + private IInputContext _input; + private ImGuiController _controller; private GL _gl; private Camera _camera; private IKeyboard _keyboard; @@ -43,6 +46,7 @@ public Snooper(UObject export) _window.Update += OnUpdate; _window.Render += OnRender; _window.Closing += OnClose; + _window.FramebufferResize += OnFramebufferResize; _grid = new Grid(); _models = new Model[1]; @@ -79,10 +83,10 @@ private void SetupCamera(FBox box) private void OnLoad() { - var input = _window.CreateInput(); - _keyboard = input.Keyboards[0]; + _input = _window.CreateInput(); + _keyboard = _input.Keyboards[0]; _keyboard.KeyDown += KeyDown; - foreach (var mouse in input.Mice) + foreach (var mouse in _input.Mice) { mouse.Cursor.CursorMode = CursorMode.Raw; mouse.MouseMove += OnMouseMove; @@ -94,6 +98,8 @@ private void OnLoad() _gl.Enable(EnableCap.DepthTest); _gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + _controller = new ImGuiController(_gl, _window, _input); + _grid.Setup(_gl); foreach (var model in _models) @@ -102,8 +108,15 @@ private void OnLoad() } } + private void OnFramebufferResize(Vector2D size) + { + _gl.Viewport(size); + } + private void OnRender(double deltaTime) { + _controller.Update((float) deltaTime); + _gl.ClearColor(0.149f, 0.149f, 0.188f, 1.0f); _gl.Clear((uint) ClearBufferMask.ColorBufferBit | (uint) ClearBufferMask.DepthBufferBit); @@ -113,6 +126,10 @@ private void OnRender(double deltaTime) { model.Bind(_camera); } + + ImGuiNET.ImGui.ShowAboutWindow(); + + _controller.Render(); } private void OnUpdate(double deltaTime) @@ -171,6 +188,9 @@ private void OnClose() { model.Dispose(); } + _input.Dispose(); + _controller.Dispose(); + _gl.Dispose(); } private void KeyDown(IKeyboard keyboard, Key key, int arg3)