From af4a114fad3bce142a0eda0a31c97c505918b2e7 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Wed, 4 May 2022 14:39:27 +0200 Subject: [PATCH] Added IMGUI --- .gitmodules | 3 + .../include/MyGraphicsEngine/Window.h | 3 + MyGraphicsEngine/window.cpp | 12 +++- SandboxApplication/Sandbox.cpp | 57 +++++++++++++++++-- imgui.ini | 15 +++++ libs/ImGui | 1 + premake5.lua | 7 ++- 7 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 imgui.ini create mode 160000 libs/ImGui diff --git a/.gitmodules b/.gitmodules index 5f32826..8ac84ea 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "GorrillaAudio"] path = libs/GorillaAudio url = https://github.com/mewspring/gorilla-audio.git +[submodule "ImGui"] + path = libs/ImGui + url = https://github.com/ocornut/imgui.git diff --git a/MyGraphicsEngine/include/MyGraphicsEngine/Window.h b/MyGraphicsEngine/include/MyGraphicsEngine/Window.h index 3cee4f1..de7ecfb 100644 --- a/MyGraphicsEngine/include/MyGraphicsEngine/Window.h +++ b/MyGraphicsEngine/include/MyGraphicsEngine/Window.h @@ -18,9 +18,12 @@ class BarinkWindow{ BarinkWindow(const int width, const int height); ~BarinkWindow(); + GLFWwindow* windowptr(); + bool WindowShouldClose(); void Poll(); + void SwapBuffers(); }; \ No newline at end of file diff --git a/MyGraphicsEngine/window.cpp b/MyGraphicsEngine/window.cpp index ca3825b..3cf8112 100644 --- a/MyGraphicsEngine/window.cpp +++ b/MyGraphicsEngine/window.cpp @@ -50,6 +50,11 @@ Width(width), Height(height), FullScreen(false){ BarinkWindow::~BarinkWindow(){ glfwTerminate(); +} + +GLFWwindow* BarinkWindow::windowptr() +{ + return window; } bool BarinkWindow::WindowShouldClose(){ @@ -58,6 +63,11 @@ bool BarinkWindow::WindowShouldClose(){ void BarinkWindow::Poll() { - glfwSwapBuffers(window); + glfwPollEvents(); +} + +void BarinkWindow::SwapBuffers() +{ + glfwSwapBuffers(window); } \ No newline at end of file diff --git a/SandboxApplication/Sandbox.cpp b/SandboxApplication/Sandbox.cpp index 0b9d35c..b11c27b 100644 --- a/SandboxApplication/Sandbox.cpp +++ b/SandboxApplication/Sandbox.cpp @@ -4,6 +4,10 @@ #include #include +#include "imgui.h" +#include "backends/imgui_impl_glfw.h" +#include "backends/imgui_impl_opengl3.h" + /* * extern "C" { @@ -11,11 +15,12 @@ #include "lua.h" #include "lualib.h" } -*/ -//#include + +#include #include #include +*/ int main(int argc, char* argv[]) { @@ -44,6 +49,16 @@ int main(int argc, char* argv[]) { BarinkWindow GameWindow(800, 600); + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + (void)io; + + ImGui::StyleColorsDark(); + ImGui_ImplGlfw_InitForOpenGL(GameWindow.windowptr(), true); + ImGui_ImplOpenGL3_Init("#version 440"); + + std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs"; std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs"; Shader shader (vertexShaderSource, fragmentShaderSource); @@ -95,7 +110,8 @@ int main(int argc, char* argv[]) { glm::mat4 projection = glm::perspective(cam.Zoom, (800.0f / 600.0f), 0.001f, 100.0f); - gau_Manager* mgr; + /* + * gau_Manager* mgr; ga_Mixer* mixer; ga_Sound sound; ga_Handle handle; @@ -108,13 +124,19 @@ int main(int argc, char* argv[]) { gc_initialize(0); mgr = gau_manager_create(); mixer = gau_manager_mixer(mgr); + */ + while (!GameWindow.WindowShouldClose()) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) ; - + + + GameWindow.Poll(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + shader.Use(); shader.setUniformMat4("P", projection); shader.setUniformMat4("M", model); @@ -124,11 +146,34 @@ int main(int argc, char* argv[]) { glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL); glBindVertexArray(0); - GameWindow.Poll(); + + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + ImGui::Begin("Test"); + + ImGui::Text("Hello world!"); + bool isChecked = false; + ImGui::Checkbox("Yellow!", &isChecked); + float v = 5; + ImGui::SliderFloat("Something to slide on..", &v, 1, 10 ); + + ImGui::End(); + + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + + GameWindow.SwapBuffers(); } + // Cleanup + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &EBO); diff --git a/imgui.ini b/imgui.ini new file mode 100644 index 0000000..b19d6c0 --- /dev/null +++ b/imgui.ini @@ -0,0 +1,15 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Test] +Pos=268,47 +Size=201,94 +Collapsed=0 + +[Window][Dear ImGui Demo] +Pos=650,20 +Size=550,680 +Collapsed=0 + diff --git a/libs/ImGui b/libs/ImGui new file mode 160000 index 0000000..6d27fec --- /dev/null +++ b/libs/ImGui @@ -0,0 +1 @@ +Subproject commit 6d27fecce1ea2cb10ca956cd67b8179cb76b35c3 diff --git a/premake5.lua b/premake5.lua index df1251b..f3447be 100644 --- a/premake5.lua +++ b/premake5.lua @@ -20,12 +20,14 @@ workspace "BarinkEngine" "./libs/GorillaAudio/include", "./libs/lua/include", "./libs/glfw/include", + "./libs/ImGui" } libdirs{ "./libs/spdlog/build/Release", "./libs/glfw/build/src/Debug", - "./libs/lua" + "./libs/lua", + "./libs/ImGui" } links{ @@ -36,6 +38,9 @@ workspace "BarinkEngine" } files { + "./libs/ImGui/*.cpp", + "./libs/ImGui/backends/imgui_impl_glfw.cpp", + "./libs/ImGui/backends/imgui_impl_Opengl3.cpp", "SandboxApplication/*.cpp" }