Skip to content

Commit

Permalink
hello imgui
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 28, 2022
1 parent 80e8f3f commit 9f3d9b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Silk.NET.Input" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" />
<PackageReference Include="Silk.NET.Windowing" Version="2.16.0" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.0" />
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
Expand Down
26 changes: 23 additions & 3 deletions FModel/Views/Snooper/Snooper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
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;

public class Snooper
{
private IWindow _window;
private IInputContext _input;
private ImGuiController _controller;
private GL _gl;
private Camera _camera;
private IKeyboard _keyboard;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -102,8 +108,15 @@ private void OnLoad()
}
}

private void OnFramebufferResize(Vector2D<int> 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);

Expand All @@ -113,6 +126,10 @@ private void OnRender(double deltaTime)
{
model.Bind(_camera);
}

ImGuiNET.ImGui.ShowAboutWindow();

_controller.Render();
}

private void OnUpdate(double deltaTime)
Expand Down Expand Up @@ -171,6 +188,9 @@ private void OnClose()
{
model.Dispose();
}
_input.Dispose();
_controller.Dispose();
_gl.Dispose();
}

private void KeyDown(IKeyboard keyboard, Key key, int arg3)
Expand Down

0 comments on commit 9f3d9b3

Please sign in to comment.