From 4c92e9f969f34c00c6accda2e73b4c9c11deb3ca Mon Sep 17 00:00:00 2001 From: Michael Baetgen Date: Sun, 14 Dec 2025 01:26:29 -0600 Subject: [PATCH 1/2] use GLAD to link OpenGL --- BUILDING-cmake.md | 1 - BUILDING.md | 5 - CMakeLists.txt | 9 - docs/building.rst | 3 - src/api/include/projectM-4/core.h | 14 + src/libprojectM/CMakeLists.txt | 6 +- src/libprojectM/MilkdropPreset/CMakeLists.txt | 1 - src/libprojectM/ProjectMCWrapper.cpp | 13 + src/libprojectM/Renderer/CMakeLists.txt | 4 + src/libprojectM/Renderer/CrossGlLoader.cpp | 309 ++ src/libprojectM/Renderer/CrossGlLoader.hpp | 126 + src/libprojectM/Renderer/OpenGL.h | 27 +- src/libprojectM/Renderer/PlatformLoader.h | 277 + src/libprojectM/UserSprites/CMakeLists.txt | 1 - src/libprojectM/projectM4Config.cmake.in | 3 - src/sdl-test-ui/CMakeLists.txt | 6 + src/sdl-test-ui/opengl.h | 4 + src/sdl-test-ui/pmSDL.cpp | 12 +- src/sdl-test-ui/pmSDL.hpp | 2 +- src/sdl-test-ui/setup.cpp | 7 - vcpkg.json | 7 +- vendor/CMakeLists.txt | 1 + vendor/SOIL2/CMakeLists.txt | 67 +- vendor/SOIL2/src/SOIL2/SOIL2.c | 521 +- vendor/SOIL2/src/SOIL2/SOIL2.h | 1 + vendor/SOIL2/src/SOIL2/soil2_gl_bridge.c | 13 + vendor/SOIL2/src/SOIL2/soil2_gl_bridge.h | 23 + vendor/glad/CMakeLists.txt | 79 + vendor/glad/include/EGL/eglplatform.h | 175 + vendor/glad/include/KHR/khrplatform.h | 311 ++ vendor/glad/include/glad/egl.h | 476 ++ vendor/glad/include/glad/gl.h | 4872 +++++++++++++++++ vendor/glad/include/glad/gles2.h | 2103 +++++++ vendor/glad/include/glad/glx.h | 567 ++ vendor/glad/include/glad/wgl.h | 299 + vendor/glad/src/egl.c | 374 ++ vendor/glad/src/gl.c | 3589 ++++++++++++ vendor/glad/src/gles2.c | 1318 +++++ vendor/glad/src/glx.c | 355 ++ vendor/glad/src/wgl.c | 136 + 40 files changed, 15741 insertions(+), 376 deletions(-) create mode 100644 src/libprojectM/Renderer/CrossGlLoader.cpp create mode 100644 src/libprojectM/Renderer/CrossGlLoader.hpp create mode 100644 src/libprojectM/Renderer/PlatformLoader.h create mode 100644 vendor/SOIL2/src/SOIL2/soil2_gl_bridge.c create mode 100644 vendor/SOIL2/src/SOIL2/soil2_gl_bridge.h create mode 100644 vendor/glad/CMakeLists.txt create mode 100644 vendor/glad/include/EGL/eglplatform.h create mode 100644 vendor/glad/include/KHR/khrplatform.h create mode 100644 vendor/glad/include/glad/egl.h create mode 100644 vendor/glad/include/glad/gl.h create mode 100644 vendor/glad/include/glad/gles2.h create mode 100644 vendor/glad/include/glad/glx.h create mode 100644 vendor/glad/include/glad/wgl.h create mode 100644 vendor/glad/src/egl.c create mode 100644 vendor/glad/src/gl.c create mode 100644 vendor/glad/src/gles2.c create mode 100644 vendor/glad/src/glx.c create mode 100644 vendor/glad/src/wgl.c diff --git a/BUILDING-cmake.md b/BUILDING-cmake.md index ee27dee7fe..d169e3815d 100644 --- a/BUILDING-cmake.md +++ b/BUILDING-cmake.md @@ -11,7 +11,6 @@ Required tools and dependencies: - CMake 3.21 or higher. - A working toolchain, e.g. Visual Studio on Windows or the `build-essentials` package on Ubuntu Linux. - Main OpenGL libraries and development files. -- The `GLEW` Library on Windows. To use the library in other projects, it is required to install it. Use `CMAKE_INSTALL_PREFIX` to specify the installation directory. diff --git a/BUILDING.md b/BUILDING.md index 9a3fe3127d..64b0415c4e 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -100,11 +100,6 @@ development files. To build projectM, both binaries and development files need t library dependencies and/or using CMake to configure the build. Mainly used on Windows, but also works for Linux and macOS. -### Only relevant for Windows: - -* [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to - configure the build, the pre-created solutions use a bundled copy of GLEW. - ## Building on Linux and macOS ### Installing dependencies diff --git a/CMakeLists.txt b/CMakeLists.txt index 32000a1bb8..6460ba08f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,15 +187,6 @@ else() if(TARGET OpenGL::GLX) list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX) endif() - if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - find_package(GLEW REQUIRED) - # Prefer shared, but check for static lib if shared is not available. - if(TARGET GLEW::glew) - list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew) - elseif(TARGET GLEW::glew_s) - list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew_s) - endif() - endif() endif() endif() diff --git a/docs/building.rst b/docs/building.rst index 9a82b2e6a4..07b8735f4c 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -138,9 +138,6 @@ Only relevant for Windows: library dependencies and/or using CMake to configure the build. - `NuGet `__: Dependency manager for .NET. Required to build the EyeTune app. -- `GLEW `__: The OpenGL Extension - Wrangler Library. Only required if using CMake to configure the - build, the pre-created solutions use a bundled copy of GLEW. Building on Linux and macOS --------------------------- diff --git a/src/api/include/projectM-4/core.h b/src/api/include/projectM-4/core.h index b54e698682..5a30564d4a 100644 --- a/src/api/include/projectM-4/core.h +++ b/src/api/include/projectM-4/core.h @@ -44,6 +44,20 @@ extern "C" { */ PROJECTM_EXPORT projectm_handle projectm_create(); + +/** + * @brief Creates a new projectM instance using the given function to resolve GL api functions. + * + * The load_proc function accepts a function name and a user data pointer. + * If this function returns NULL, in most cases the OpenGL context is not initialized, not made + * current or insufficient to render projectM visuals. + * + * @return A projectM handle for the newly created instance that must be used in subsequent API calls. + * NULL if the instance could not be created successfully. + * @since 4.2.0 + */ +PROJECTM_EXPORT projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data); + /** * @brief Destroys the given instance and frees the resources. * diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index 2fc1c3160e..6f19247281 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -6,6 +6,10 @@ add_compile_definitions( $,STBI_NO_DDS,> ) +include_directories( + "${PROJECTM_SOURCE_DIR}/vendor/glad/include" + ) + add_subdirectory(Audio) add_subdirectory(MilkdropPreset) add_subdirectory(Renderer) @@ -70,6 +74,7 @@ add_library(projectM $ $ $ + $ ) target_include_directories(projectM @@ -79,7 +84,6 @@ target_include_directories(projectM target_link_libraries(projectM PUBLIC - ${PROJECTM_OPENGL_LIBRARIES} libprojectM::API ${PROJECTM_FILESYSTEM_LIBRARY} ) diff --git a/src/libprojectM/MilkdropPreset/CMakeLists.txt b/src/libprojectM/MilkdropPreset/CMakeLists.txt index 6889d8ad2f..3231a97279 100644 --- a/src/libprojectM/MilkdropPreset/CMakeLists.txt +++ b/src/libprojectM/MilkdropPreset/CMakeLists.txt @@ -140,7 +140,6 @@ target_link_libraries(MilkdropPreset PUBLIC hlslparser GLM::GLM - ${PROJECTM_OPENGL_LIBRARIES} ) if(NOT BUILD_SHARED_LIBS) diff --git a/src/libprojectM/ProjectMCWrapper.cpp b/src/libprojectM/ProjectMCWrapper.cpp index 0c89ba64e2..f7e078e3ab 100644 --- a/src/libprojectM/ProjectMCWrapper.cpp +++ b/src/libprojectM/ProjectMCWrapper.cpp @@ -1,11 +1,15 @@ #include "ProjectMCWrapper.hpp" +#include #include #include #include