From bae1f05038744490082487f8ccc32437b873e5d2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 16 May 2021 13:04:32 -0500 Subject: [PATCH] [nostalgia] Add scaffolding for ImGui --- .gitignore | 1 + CMakeLists.txt | 13 +++++++-- conanfile.py | 8 +++++- deps/imgui/CMakeLists.txt | 40 ++++++++++++++++++++++++++ src/nostalgia/core/glfw/CMakeLists.txt | 10 +++++++ src/nostalgia/core/glfw/core.hpp | 2 +- src/nostalgia/core/glfw/gfx.cpp | 3 ++ 7 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 deps/imgui/CMakeLists.txt diff --git a/.gitignore b/.gitignore index d44d4288..5defd653 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .clangd .current_build scripts/__pycache__ +deps/imgui/src compile_commands.json build .conanbuild diff --git a/CMakeLists.txt b/CMakeLists.txt index eee646c3..91bb4789 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,12 +44,19 @@ else() endif() add_subdirectory(deps/ox) -include_directories(SYSTEM deps/ox/src) +include_directories( + SYSTEM + deps/imgui/src + deps/ox/src +) if(BUILDCORE_TARGET STREQUAL "gba") add_subdirectory(deps/gbastartup) -elseif(NOSTALGIA_BUILD_STUDIO) - add_subdirectory(deps/QDark) +else() + if(NOSTALGIA_BUILD_STUDIO) + add_subdirectory(deps/QDark) + endif() + add_subdirectory(deps/imgui) endif() add_subdirectory(src) diff --git a/conanfile.py b/conanfile.py index c5e3caef..35a261d2 100644 --- a/conanfile.py +++ b/conanfile.py @@ -2,7 +2,13 @@ from conans import ConanFile, CMake class NostalgiaConan(ConanFile): settings = 'os', 'compiler', 'build_type', 'arch' - requires = 'jsoncpp/1.9.4', 'glfw/3.3.4' + requires = 'jsoncpp/1.9.4', 'glfw/3.3.4', 'imgui/1.82' generators = 'cmake', 'cmake_find_package', 'cmake_paths' default_options = { } + + def imports(self): + self.copy('imgui_impl_glfw.cpp', dst='../deps/imgui/src', src='./res/bindings') + self.copy('imgui_impl_opengl3.cpp', dst='../deps/imgui/src', src='./res/bindings') + self.copy('imgui_impl_glfw.h', dst='../deps/imgui/src', src='./res/bindings') + self.copy('imgui_impl_opengl3.h', dst='../deps/imgui/src', src='./res/bindings') diff --git a/deps/imgui/CMakeLists.txt b/deps/imgui/CMakeLists.txt new file mode 100644 index 00000000..01ad6245 --- /dev/null +++ b/deps/imgui/CMakeLists.txt @@ -0,0 +1,40 @@ +add_library( + imgui-glfw + src/imgui_impl_glfw.cpp + src/imgui_impl_opengl3.cpp +) + +find_package(glfw3 REQUIRED) +find_package(imgui REQUIRED) + +if(APPLE) + target_compile_definitions( + imgui-glfw PRIVATE + IMGUI_IMPL_OPENGL_LOADER_CUSTOM="OpenGL/gl3.h" + ) +endif() + +target_link_libraries( + imgui-glfw PUBLIC + ${OPENGL_gl_LIBRARY} + glfw::glfw + imgui::imgui +) + +if(NOT MSVC) + target_compile_options( + imgui-glfw PRIVATE + -Wno-all + -Wno-extra + -Wno-old-style-cast + -Wno-deprecated-declarations + ) +endif() + +install( + TARGETS + imgui-glfw + DESTINATION + LIBRARY DESTINATION lib/nostalgia + ARCHIVE DESTINATION lib/nostalgia +) diff --git a/src/nostalgia/core/glfw/CMakeLists.txt b/src/nostalgia/core/glfw/CMakeLists.txt index 802c7af7..036dc166 100644 --- a/src/nostalgia/core/glfw/CMakeLists.txt +++ b/src/nostalgia/core/glfw/CMakeLists.txt @@ -5,10 +5,20 @@ add_library( ) find_package(glfw3 REQUIRED) +find_package(imgui REQUIRED) + +if(APPLE) + find_package(OpenGL REQUIRED) +else() + set(OPENGL_gl_LIBRARY GL) +endif() target_link_libraries( NostalgiaCore-GLFW PUBLIC + ${OPENGL_gl_LIBRARY} glfw::glfw + imgui::imgui + imgui-glfw NostalgiaGlUtils NostalgiaCore-Userspace ) diff --git a/src/nostalgia/core/glfw/core.hpp b/src/nostalgia/core/glfw/core.hpp index 9c79e230..eca68d56 100644 --- a/src/nostalgia/core/glfw/core.hpp +++ b/src/nostalgia/core/glfw/core.hpp @@ -13,7 +13,7 @@ namespace nostalgia::core { struct GlfwImplData { - class GLFWwindow *window = nullptr; + struct GLFWwindow *window = nullptr; int64_t startTime = 0; bool running = false; event_handler eventHandler = nullptr; diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index e41600f5..27978cc4 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -7,6 +7,8 @@ */ #include +#include +#include #include @@ -37,6 +39,7 @@ ox::Error initGfx(Context *ctx) noexcept { glfwSetWindowUserPointer(id->window, ctx); glfwMakeContextCurrent(id->window); oxReturnError(renderer::init(ctx)); + ImGui_ImplGlfw_InitForOpenGL(id->window, true); return OxError(0); }