diff --git a/.gitmodules b/.gitmodules index 41c1d61..08fde64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/easyloggingpp"] path = lib/easyloggingpp url = git@github.com:amrayn/easyloggingpp.git +[submodule "lib/imgui"] + path = lib/imgui + url = git@github.com:ocornut/imgui.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 658a145..b7dca6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,10 +11,23 @@ include_directories("src/") include_directories("gl/include") include_directories("lib/easyloggingpp/src") add_subdirectory(lib/glm EXCLUDE_FROM_ALL) +include_directories("lib/imgui") +include_directories("lib/imgui/backends") add_subdirectory(src) add_subdirectory(src/animation) add_subdirectory(src/demo) +set(SOURCE + ${SOURCE} + ${CMAKE_SOURCE_DIR}/lib/imgui/imgui.cpp + ${CMAKE_SOURCE_DIR}/lib/imgui/imgui_demo.cpp + ${CMAKE_SOURCE_DIR}/lib/imgui/imgui_draw.cpp + ${CMAKE_SOURCE_DIR}/lib/imgui/imgui_tables.cpp + ${CMAKE_SOURCE_DIR}/lib/imgui/imgui_widgets.cpp + ${CMAKE_SOURCE_DIR}/lib/imgui/backends/imgui_impl_glfw.cpp + ${CMAKE_SOURCE_DIR}/lib/imgui/backends/imgui_impl_opengl3.cpp + ) + add_executable(demo main.cpp gl/src/glad.c ${SOURCE} lib/easyloggingpp/src/easylogging++.cc) target_link_libraries(demo glfw OpenGL::GL) \ No newline at end of file diff --git a/lib/imgui b/lib/imgui new file mode 160000 index 0000000..0468997 --- /dev/null +++ b/lib/imgui @@ -0,0 +1 @@ +Subproject commit 04689979b49a1b519c9f5bed4d4f143eeae87782 diff --git a/main.cpp b/main.cpp index b557941..b87737f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,9 @@ #include +#include "imgui.h" +#include "imgui_impl_glfw.h" +#include "imgui_impl_opengl3.h" + #include "peripherals_glfw.h" #include "demo/demo_engine.h" #include "timer.h" @@ -208,8 +212,49 @@ int main() { glBindFramebuffer(GL_FRAMEBUFFER, 0); + + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + ImGui::StyleColorsDark(); + + // Setup Platform/Renderer backends + ImGui_ImplGlfw_InitForOpenGL(((peripherals_glfw*)&peripherals)->get_window(), true); + ImGui_ImplOpenGL3_Init("#version 150"); + timer timer1; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + bool show_demo_window = false; + bool show_another_window = false; + while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) { + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + { + static float f = 0.0f; + static int counter = 0; + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) + ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + ImGui::Checkbox("Another Window", &show_another_window); + + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color + + if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + ImGui::SameLine(); + ImGui::Text("counter = %d", counter); + + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::End(); + } + + double elapsedSeconds = timer1.seconds_since_start(); bigSphere->mesh_ = mesh_generator::extrude(mesh_generator::sphere(50, 50), {200, 201, 100, 101, 400, 401}, 0.05, (int) ((sin(elapsedSeconds) + 0.5) * 40)); @@ -231,6 +276,9 @@ int main() { demoPartClear.process(demoPartClear.normalizeTime(elapsedSeconds)); demoPartScene.process(demoPartScene.normalizeTime(elapsedSeconds)); + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + peripherals.swap_buffers(); peripherals.poll_events(); } diff --git a/src/peripherals_glfw.cpp b/src/peripherals_glfw.cpp index 8c3688d..7cd164c 100644 --- a/src/peripherals_glfw.cpp +++ b/src/peripherals_glfw.cpp @@ -72,4 +72,8 @@ bool peripherals_glfw::should_close() { return glfwWindowShouldClose(window); } +GLFWwindow *peripherals_glfw::get_window() const { + return window; +} + END_NAMESPACE \ No newline at end of file diff --git a/src/peripherals_glfw.h b/src/peripherals_glfw.h index e934f52..fe3ab79 100644 --- a/src/peripherals_glfw.h +++ b/src/peripherals_glfw.h @@ -13,6 +13,7 @@ public: void swap_buffers() override; void poll_events() override; bool should_close() override; + GLFWwindow* get_window() const; ::GLFWwindow *window; };