theUpsider

OpenTKImGuiService

Jul 13th, 2025
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | Gaming | 0 0
  1. using Dear_ImGui_Sample;
  2. using EduEngine.Graphics.Interfaces;
  3. using OpenTK.Mathematics;
  4. using OpenTK.Windowing.Desktop;
  5.  
  6. namespace EduEngine.Graphics.OpenTK;
  7.  
  8. public class OpenTKImGuiService : IDebugGuiService
  9. {
  10.     private readonly ImGuiController _controller;
  11.     private readonly GameWindow _window;
  12.     private bool _disposed;
  13.  
  14.     public OpenTKImGuiService(GameWindow window)
  15.     {
  16.         _window = window;
  17.         _controller = new ImGuiController(window.ClientSize.X, window.ClientSize.Y);
  18.     }
  19.  
  20.     public void Initialize(int width, int height) =>
  21.         _controller.WindowResized(width, height);
  22.  
  23.     public void Update(float deltaTime) =>
  24.         _controller.Update(_window, deltaTime);
  25.  
  26.     public void Render()
  27.     {
  28.         _controller.Render();
  29.         ImGuiController.CheckGLError("End of frame");
  30.     }
  31.  
  32.     public void OnResize(int width, int height) =>
  33.         _controller.WindowResized(width, height);
  34.  
  35.     public void OnTextInput(char unicode) =>
  36.         _controller.PressChar(unicode);
  37.  
  38.     public void OnMouseScroll(Vector2 offset) =>
  39.         _controller.MouseScroll(offset);
  40.  
  41.     public void Dispose()
  42.     {
  43.         if (!_disposed)
  44.         {
  45.             _controller.Dispose();
  46.             _disposed = true;
  47.         }
  48.         GC.SuppressFinalize(this);
  49.     }
  50. }
Tags: eduengine
Advertisement
Add Comment
Please, Sign In to add comment