Added ImGui dependency and hooked it up

This commit is contained in:
Maddy Thorson 2021-02-16 22:56:49 -08:00
parent 3aff5a3c3f
commit 71d17afa78
4 changed files with 43 additions and 5 deletions

View File

@ -1,5 +1,5 @@
FileVersion = 1 FileVersion = 1
Dependencies = {corlib = "*", SDL2 = "*", MiniZ = "*"} Dependencies = {corlib = "*", SDL2 = "*", MiniZ = "*", ImGui = "*", ImGuiImplSDL = "*", ImGuiImplOpenGL3 = "*"}
[Project] [Project]
Name = "Strawberry" Name = "Strawberry"

View File

@ -5,6 +5,7 @@ using System.Reflection;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using ImGui;
namespace Strawberry namespace Strawberry
{ {
@ -159,8 +160,9 @@ namespace Strawberry
private void Render() private void Render()
{ {
PlatformLayer.RenderBegin(); PlatformLayer.GameRenderBegin();
Draw(); Draw();
PlatformLayer.GameRenderEnd();
PlatformLayer.RenderEnd(); PlatformLayer.RenderEnd();
} }

View File

@ -16,7 +16,10 @@ namespace Strawberry
public abstract bool Closed(); // Returns whether the game window has been closed public abstract bool Closed(); // Returns whether the game window has been closed
//Rendering //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(); public abstract void RenderEnd();
//Update //Update

View File

@ -1,6 +1,7 @@
using SDL2; using SDL2;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using ImGui;
namespace Strawberry.SDL2 namespace Strawberry.SDL2
{ {
@ -128,6 +129,15 @@ namespace Strawberry.SDL2
for (let i < gamepads.Count) for (let i < gamepads.Count)
gamepads[i] = SDL.GameControllerOpen((int32)i); gamepads[i] = SDL.GameControllerOpen((int32)i);
} }
//ImGui
{
ImGui.CHECKVERSION();
ImGui.CreateContext();
ImGui.StyleColorsDark();
ImGuiImplSDL2.InitForOpenGL(window, &glContext);
ImGuiImplOpenGL3.Init();
}
} }
public ~this() public ~this()
@ -139,6 +149,12 @@ namespace Strawberry.SDL2
SDL.GL_DeleteContext(glContext); SDL.GL_DeleteContext(glContext);
SDL.DestroyWindow(window); SDL.DestroyWindow(window);
SDL.Quit(); SDL.Quit();
#if EDITOR
ImGui.ImGuiImplOpenGL3.Shutdown();
ImGui.ImGuiImplSDL2.Shutdown();
ImGui.ImGui.DestroyContext();
#endif
} }
static void* SdlGetProcAddress(StringView string) static void* SdlGetProcAddress(StringView string)
@ -154,7 +170,20 @@ namespace Strawberry.SDL2
public override uint32 Ticks => SDL.GetTicks(); 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.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
GL.glClearColor(Game.ClearColor.Rf, Game.ClearColor.Gf, Game.ClearColor.Bf, Game.ClearColor.Af); GL.glClearColor(Game.ClearColor.Rf, Game.ClearColor.Gf, Game.ClearColor.Bf, Game.ClearColor.Af);
@ -162,10 +191,14 @@ namespace Strawberry.SDL2
GL.glUseProgram(glProgram); GL.glUseProgram(glProgram);
} }
public override void RenderEnd() public override void GameRenderEnd()
{ {
GL.glUseProgram(0); GL.glUseProgram(0);
GL.glFlush(); GL.glFlush();
}
public override void RenderEnd()
{
SDL.GL_SwapWindow(window); SDL.GL_SwapWindow(window);
} }