From 4391028e7000bef4e961d64db0b97da53b6dda69 Mon Sep 17 00:00:00 2001 From: Kristian Ollikainen Date: Mon, 18 Mar 2024 21:16:47 +0200 Subject: [PATCH] Build: glbinding is back, except for nix I just love C++, nix hates glbinding for some reason --- CMakeLists.txt | 3 ++- Source/CMakeLists.txt | 8 ++++---- Source/gui.cppm | 26 +++++++++++++++++++++----- Source/notification.cppm | 3 +-- cmake/modules/FetchDeps.cmake | 10 ++++++++++ flake.lock | 6 +++--- flake.nix | 1 - 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f3fc9..04a3416 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,16 +41,17 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) find_package(fmt REQUIRED) -find_package(gl3w REQUIRED) find_package(glfw3 REQUIRED) find_package(websocketpp REQUIRED) if (NON_NIX_BUILD) + find_package(glbinding REQUIRED) find_package(ogg REQUIRED) find_package(opus REQUIRED) find_package(opusfile REQUIRED) else() find_package(PkgConfig REQUIRED) + find_package(gl3w REQUIRED) pkg_check_modules(asio REQUIRED IMPORTED_TARGET asio) pkg_check_modules(ogg REQUIRED IMPORTED_TARGET ogg) pkg_check_modules(opus REQUIRED IMPORTED_TARGET opus) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 7ac8bb5..a7a9dd4 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -38,11 +38,13 @@ target_include_directories(ChatNotifier BEFORE PRIVATE target_link_libraries(ChatNotifier PRIVATE fmt::fmt-header-only - gl3w + miniaudio glfw - $<$:asio> + $<$:glbinding::glbinding> + $<$>:gl3w> + $<$:asio> $<$:ogg> $<$:opus> $<$:OpusFile::opusfile> @@ -50,8 +52,6 @@ target_link_libraries(ChatNotifier PRIVATE ${ogg_LIBRARIES} ${opus_LIBRARIES} ${opusfile_LIBRARIES} - - miniaudio ) if (WIN32) diff --git a/Source/gui.cppm b/Source/gui.cppm index 65f2ce8..610065f 100644 --- a/Source/gui.cppm +++ b/Source/gui.cppm @@ -1,8 +1,16 @@ module; -#define GLFW_INCLUDE_NONE // Don't include OpenGL headers, we are using gl3w - +#define GLFW_INCLUDE_NONE // Don't include OpenGL headers, we are using glbinding +#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM // Same goes for ImGui + +#if __has_include() +#define GL_LOADER_GLBINDING +#include +#include +#else #include +#endif + #include #include #include @@ -24,6 +32,10 @@ import notification; import twitch; import commands; +#ifdef GL_LOADER_GLBINDING +using namespace gl; +#endif + // Class which manages the GUI + notifications export class NotifierGUI { static inline bool m_keepRunning = false; @@ -73,15 +85,19 @@ public: glfwMakeContextCurrent(m_mainWindow); glfwSwapInterval(1); // V-Sync - // GL3W INITIALIZATION // + // GLBINDING/GL3W INITIALIZATION // +#ifdef GL_LOADER_GLBINDING + glbinding::initialize(glfwGetProcAddress, false); +#else if (gl3wInit()) { - fmt::println(stderr, "Failed to initialize GL3W"); + fmt::print(stderr, "Failed to initialize OpenGL loader!\n"); return; } if (!gl3wIsSupported(3, 3)) { - fmt::println(stderr, "OpenGL 3.3 not supported"); + fmt::print(stderr, "OpenGL 3.3 not supported!\n"); return; } +#endif // Print OpenGL version fmt::println("OpenGL Version: {}", get_gl_string(GL_VERSION)); diff --git a/Source/notification.cppm b/Source/notification.cppm index 2ea495c..262a159 100644 --- a/Source/notification.cppm +++ b/Source/notification.cppm @@ -61,7 +61,6 @@ public: viewport->Flags |= ImGuiViewportFlags_NoInputs; viewport->Flags |= ImGuiViewportFlags_NoFocusOnAppearing; viewport->Flags |= ImGuiViewportFlags_NoFocusOnClick; - viewport->Flags |= ImGuiViewportFlags_NoAutoMerge; viewport->Flags |= ImGuiViewportFlags_NoTaskBarIcon; viewport->Flags |= ImGuiViewportFlags_NoDecoration; @@ -96,7 +95,7 @@ public: // Animate appearing from top, fading away at center const auto offset = - std::lerp(-totalTextHeight / 2.0f, + std::lerp(-totalTextHeight, ImGui::GetWindowHeight() / 2.0f - totalTextHeight / 2.0f, timeT) + lineY; diff --git a/cmake/modules/FetchDeps.cmake b/cmake/modules/FetchDeps.cmake index c849f67..06af8dc 100644 --- a/cmake/modules/FetchDeps.cmake +++ b/cmake/modules/FetchDeps.cmake @@ -75,6 +75,16 @@ FetchContent_Declare( # While fmt has C++20 modules, the CMake script they have for it is broken.. FetchContent_MakeAvailable(fmt) +# Fetch glbinding +message(STATUS "Fetching glbinding") +FetchContent_Declare( + glbinding + GIT_REPOSITORY "https://github.com/cginternals/glbinding.git" + GIT_TAG "v3.3.0" + OVERRIDE_FIND_PACKAGE +) +FetchContent_MakeAvailable(glbinding) + # Fetch glfw message(STATUS "Fetching GLFW") FetchContent_Declare( diff --git a/flake.lock b/flake.lock index 3a04a4c..e73ef57 100644 --- a/flake.lock +++ b/flake.lock @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710272261, - "narHash": "sha256-g0bDwXFmTE7uGDOs9HcJsfLFhH7fOsASbAuOzDC+fhQ=", + "lastModified": 1710631334, + "narHash": "sha256-rL5LSYd85kplL5othxK5lmAtjyMOBg390sGBTb3LRMM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0ad13a6833440b8e238947e47bea7f11071dc2b2", + "rev": "c75037bbf9093a2acb617804ee46320d6d1fea5a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 11b0e97..3d2ac1d 100644 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,6 @@ buildInputs = with targetPkgs; [ asio fmt - glbinding glfw gl3w libogg