Skip to content

Commit

Permalink
Initialize GLEW if libprojectM uses it.
Browse files Browse the repository at this point in the history
  • Loading branch information
kblaschke committed Apr 22, 2024
1 parent cb6c2ff commit fc03b87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"
)
Expand Down
16 changes: 16 additions & 0 deletions src/SDLRenderingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#include <Poco/Util/Application.h>

#ifdef USE_GLEW
#include <GL/glew.h>
#endif

#include <SDL2/SDL_opengl.h>

const char* SDLRenderingWindow::name() const
Expand Down Expand Up @@ -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<const char*>(glewGetErrorString(glewError)));
poco_fatal(_logger, errorMessage);
throw Poco::Exception(errorMessage);
}

poco_debug_f1(_logger, "Initialized GLEW: %s", std::string(reinterpret_cast<const char*>(glewGetString(GLEW_VERSION))));
#endif

if (_config->getBool("fullscreen", false))
{
Fullscreen();
Expand Down

0 comments on commit fc03b87

Please sign in to comment.