diff --git a/BeefProj.toml b/BeefProj.toml index ee19c67..98f1e16 100644 --- a/BeefProj.toml +++ b/BeefProj.toml @@ -1,5 +1,5 @@ FileVersion = 1 -Dependencies = {corlib = "*", SDL2 = "*", MiniZ = "*"} +Dependencies = {corlib = "*", SDL2 = "*", MiniZ = "*", ImGui = "*", ImGuiImplSDL = "*", ImGuiImplOpenGL3 = "*"} [Project] Name = "Strawberry" diff --git a/src/Core/Game.bf b/src/Core/Game.bf index cde21e0..98d6c42 100644 --- a/src/Core/Game.bf +++ b/src/Core/Game.bf @@ -5,6 +5,7 @@ using System.Reflection; using System.IO; using System.Diagnostics; using System.Threading; +using ImGui; namespace Strawberry { @@ -159,8 +160,9 @@ namespace Strawberry private void Render() { - PlatformLayer.RenderBegin(); + PlatformLayer.GameRenderBegin(); Draw(); + PlatformLayer.GameRenderEnd(); PlatformLayer.RenderEnd(); } diff --git a/src/PlatformLayer/PlatformLayer.bf b/src/PlatformLayer/PlatformLayer.bf index 4d5fbf4..4e6011b 100644 --- a/src/PlatformLayer/PlatformLayer.bf +++ b/src/PlatformLayer/PlatformLayer.bf @@ -16,7 +16,10 @@ namespace Strawberry public abstract bool Closed(); // Returns whether the game window has been closed //Rendering - public abstract void RenderBegin(); + public abstract void EditorRenderBegin(); + public abstract void EditorRenderEnd(); + public abstract void GameRenderBegin(); + public abstract void GameRenderEnd(); public abstract void RenderEnd(); //Update diff --git a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf index 45f7440..c7c3438 100644 --- a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf +++ b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf @@ -1,6 +1,7 @@ using SDL2; using System; using System.Diagnostics; +using ImGui; namespace Strawberry.SDL2 { @@ -128,6 +129,15 @@ namespace Strawberry.SDL2 for (let i < gamepads.Count) gamepads[i] = SDL.GameControllerOpen((int32)i); } + + //ImGui + { + ImGui.CHECKVERSION(); + ImGui.CreateContext(); + ImGui.StyleColorsDark(); + ImGuiImplSDL2.InitForOpenGL(window, &glContext); + ImGuiImplOpenGL3.Init(); + } } public ~this() @@ -139,6 +149,12 @@ namespace Strawberry.SDL2 SDL.GL_DeleteContext(glContext); SDL.DestroyWindow(window); SDL.Quit(); + + #if EDITOR + ImGui.ImGuiImplOpenGL3.Shutdown(); + ImGui.ImGuiImplSDL2.Shutdown(); + ImGui.ImGui.DestroyContext(); + #endif } static void* SdlGetProcAddress(StringView string) @@ -154,7 +170,20 @@ namespace Strawberry.SDL2 public override uint32 Ticks => SDL.GetTicks(); - public override void RenderBegin() + public override void EditorRenderBegin() + { + ImGuiImplOpenGL3.NewFrame(); + ImGuiImplSDL2.NewFrame(window); + ImGui.NewFrame(); + } + + public override void EditorRenderEnd() + { + ImGui.Render(); + ImGuiImplOpenGL3.RenderDrawData(ImGui.ImGui.GetDrawData()); + } + + public override void GameRenderBegin() { GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); GL.glClearColor(Game.ClearColor.Rf, Game.ClearColor.Gf, Game.ClearColor.Bf, Game.ClearColor.Af); @@ -162,10 +191,14 @@ namespace Strawberry.SDL2 GL.glUseProgram(glProgram); } - public override void RenderEnd() + public override void GameRenderEnd() { GL.glUseProgram(0); GL.glFlush(); + } + + public override void RenderEnd() + { SDL.GL_SwapWindow(window); }