From 2fb85dc9a2f5b886bd3efcdc1f9b7fabdba4f0b1 Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 16 Dec 2023 01:32:25 -0500 Subject: [PATCH] imgui working --- commit.sh | 4 ++++ src/blt/gfx/window.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 3 ++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 commit.sh diff --git a/commit.sh b/commit.sh new file mode 100755 index 0000000..0471948 --- /dev/null +++ b/commit.sh @@ -0,0 +1,4 @@ +#!/bin/bash +git add * +git commit +git push -u origin main diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index 92ae633..ba96006 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include "backends/imgui_impl_opengl3.h" +#include "backends/imgui_impl_glfw.h" void error_callback(int error, const char* description) { @@ -86,6 +89,30 @@ namespace blt::gfx }); } + void setup_ImGUI() + { + const char* glsl_version = "#version 100"; + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsLight(); + + // Setup Platform/Renderer backends + ImGui_ImplGlfw_InitForOpenGL(window_state.window, true); + ImGui_ImplOpenGL3_Init(glsl_version); + +#ifdef __EMSCRIPTEN__ + io.IniFilename = nullptr; +#endif + } + void init(const window_data& data) { /* -- Setup Error Callback -- */ @@ -107,8 +134,13 @@ namespace blt::gfx glfwSwapInterval(data.sync_interval); gladLoadGL(glfwGetProcAddress); + /* -- Setup our local callbacks, ImGUI will then call these -- */ create_callbacks(); + /* -- Setup ImGUI -- */ + setup_ImGUI(); + + /* -- Call User Provided post-window-init function -- */ data.init(); @@ -118,10 +150,21 @@ namespace blt::gfx /* -- Get the current framebuffer size, update the global width/height state, along with OpenGL viewport -- */ glfwGetFramebufferSize(window_state.window, &window_state.width, &window_state.height); glViewport(0, 0, window_state.width, window_state.height); + // TODO: user option for this + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* -- Begin the next ImGUI frame -- */ + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); /* -- Call user update function -- */ data.update(window_state.width, window_state.height); + /* -- Render the ImGUI frame -- */ + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + /* -- Update GLFW state -- */ glfwSwapBuffers(window_state.window); glfwPollEvents(); @@ -130,6 +173,10 @@ namespace blt::gfx void cleanup() { + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + glfwDestroyWindow(window_state.window); glfwTerminate(); } diff --git a/src/main.cpp b/src/main.cpp index bc7c634..5698959 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include +#include void init() { @@ -9,7 +10,7 @@ void init() void update(std::int32_t width, std::int32_t height) { - + ImGui::ShowDemoWindow(); } int main()