Skip to content

Commit

Permalink
Build: glbinding is back, except for nix
Browse files Browse the repository at this point in the history
I just love C++, nix hates glbinding for some reason
  • Loading branch information
DatCaptainHorse committed Mar 18, 2024
1 parent eec96e7 commit 4391028
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ target_include_directories(ChatNotifier BEFORE PRIVATE

target_link_libraries(ChatNotifier PRIVATE
fmt::fmt-header-only
gl3w
miniaudio
glfw

$<$<BOOL:${NON_NIX_BUILD}>:asio>
$<$<BOOL:${NON_NIX_BUILD}>:glbinding::glbinding>
$<$<NOT:$<BOOL:${NON_NIX_BUILD}>>:gl3w>

$<$<BOOL:${NON_NIX_BUILD}>:asio>
$<$<BOOL:${NON_NIX_BUILD}>:ogg>
$<$<BOOL:${NON_NIX_BUILD}>:opus>
$<$<BOOL:${NON_NIX_BUILD}>:OpusFile::opusfile>

${ogg_LIBRARIES}
${opus_LIBRARIES}
${opusfile_LIBRARIES}

miniaudio
)

if (WIN32)
Expand Down
26 changes: 21 additions & 5 deletions Source/gui.cppm
Original file line number Diff line number Diff line change
@@ -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(<glbinding/glbinding.h>)
#define GL_LOADER_GLBINDING
#include <glbinding/glbinding.h>
#include <glbinding/gl33core/gl.h>
#else
#include <gl3w/GL/gl3w.h>
#endif

#include <GLFW/glfw3.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions Source/notification.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions cmake/modules/FetchDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
buildInputs = with targetPkgs; [
asio
fmt
glbinding
glfw
gl3w
libogg
Expand Down

0 comments on commit 4391028

Please sign in to comment.