From fc03b875dcec34421f6433efb16944f16e329a3e Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Mon, 22 Apr 2024 16:03:06 +0200 Subject: [PATCH] Initialize GLEW if libprojectM uses it. --- src/CMakeLists.txt | 8 ++++++++ src/SDLRenderingWindow.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fb61fd..fb65c11 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,14 @@ else() ) endif() +# GLEW needs to be initialized if libprojectM depends on it. +if(TARGET GLEW::glew OR TARGET GLEW::glew_s) + target_compile_definitions(projectMSDL + PRIVATE + USE_GLEW + ) +endif() + set_source_files_properties(ProjectMSDLApplication.cpp PROPERTIES COMPILE_DEFINITIONS PROJECTMSDL_CONFIG_LOCATION=\"${DEFAULT_CONFIG_PATH}\" ) diff --git a/src/SDLRenderingWindow.cpp b/src/SDLRenderingWindow.cpp index 4bb4061..efac35e 100644 --- a/src/SDLRenderingWindow.cpp +++ b/src/SDLRenderingWindow.cpp @@ -8,6 +8,10 @@ #include +#ifdef USE_GLEW +#include +#endif + #include const char* SDLRenderingWindow::name() const @@ -266,6 +270,18 @@ void SDLRenderingWindow::CreateSDLWindow() SDL_GL_MakeCurrent(_renderingWindow, _glContext); UpdateSwapInterval(); +#ifdef USE_GLEW + auto glewError = glewInit(); + if (glewError != GLEW_OK) + { + auto errorMessage = "Could not initialize GLEW. Error: " + std::string(reinterpret_cast(glewGetErrorString(glewError))); + poco_fatal(_logger, errorMessage); + throw Poco::Exception(errorMessage); + } + + poco_debug_f1(_logger, "Initialized GLEW: %s", std::string(reinterpret_cast(glewGetString(GLEW_VERSION)))); +#endif + if (_config->getBool("fullscreen", false)) { Fullscreen();