Skip to content

Commit bfd5253

Browse files
committed
use GLAD to link OpenGL
1 parent 0a4a2b5 commit bfd5253

40 files changed

Lines changed: 15724 additions & 386 deletions

BUILDING-cmake.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Required tools and dependencies:
1111
- CMake 3.21 or higher.
1212
- A working toolchain, e.g. Visual Studio on Windows or the `build-essentials` package on Ubuntu Linux.
1313
- Main OpenGL libraries and development files.
14-
- The `GLEW` Library on Windows.
1514

1615
To use the library in other projects, it is required to install it. Use `CMAKE_INSTALL_PREFIX` to specify the
1716
installation directory.

BUILDING.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ development files. To build projectM, both binaries and development files need t
100100
library dependencies and/or using CMake to configure the build. Mainly used on Windows, but also works for Linux and
101101
macOS.
102102

103-
### Only relevant for Windows:
104-
105-
* [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to
106-
configure the build, the pre-created solutions use a bundled copy of GLEW.
107-
108103
## Building on Linux and macOS
109104

110105
### Installing dependencies

CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,6 @@ else()
187187
if(TARGET OpenGL::GLX)
188188
list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX)
189189
endif()
190-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
191-
find_package(GLEW REQUIRED)
192-
# Prefer shared, but check for static lib if shared is not available.
193-
if(TARGET GLEW::glew)
194-
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew)
195-
elseif(TARGET GLEW::glew_s)
196-
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew_s)
197-
endif()
198-
endif()
199190
endif()
200191
endif()
201192

docs/building.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ Only relevant for Windows:
138138
library dependencies and/or using CMake to configure the build.
139139
- `NuGet <https://www.nuget.org/>`__: Dependency manager for .NET.
140140
Required to build the EyeTune app.
141-
- `GLEW <http://glew.sourceforge.net/>`__: The OpenGL Extension
142-
Wrangler Library. Only required if using CMake to configure the
143-
build, the pre-created solutions use a bundled copy of GLEW.
144141

145142
Building on Linux and macOS
146143
---------------------------

src/api/include/projectM-4/core.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ extern "C" {
4444
*/
4545
PROJECTM_EXPORT projectm_handle projectm_create();
4646

47+
48+
/**
49+
* @brief Creates a new projectM instance using the given function to resolve GL api functions.
50+
*
51+
* The load_proc function accepts a function name and a user data pointer.
52+
* If this function returns NULL, in most cases the OpenGL context is not initialized, not made
53+
* current or insufficient to render projectM visuals.
54+
*
55+
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
56+
* NULL if the instance could not be created successfully.
57+
* @since 4.2.0
58+
*/
59+
PROJECTM_EXPORT projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data);
60+
4761
/**
4862
* @brief Destroys the given instance and frees the resources.
4963
*

src/libprojectM/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ add_compile_definitions(
66
$<IF:$<PLATFORM_ID:Windows>,STBI_NO_DDS,>
77
)
88

9+
include_directories(
10+
"${PROJECTM_SOURCE_DIR}/vendor/glad/include"
11+
)
12+
913
add_subdirectory(Audio)
1014
add_subdirectory(MilkdropPreset)
1115
add_subdirectory(Renderer)
@@ -48,6 +52,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
4852
target_link_libraries(projectM_main
4953
PUBLIC
5054
"-framework CoreFoundation"
55+
"-framework OpenGL"
5156
)
5257
endif()
5358

@@ -73,6 +78,7 @@ add_library(projectM
7378
$<TARGET_OBJECTS:SOIL2>
7479
$<TARGET_OBJECTS:projectM_main>
7580
$<TARGET_OBJECTS:projectM::Eval>
81+
$<TARGET_OBJECTS:glad_obj>
7682
)
7783

7884
target_include_directories(projectM
@@ -82,7 +88,6 @@ target_include_directories(projectM
8288

8389
target_link_libraries(projectM
8490
PUBLIC
85-
${PROJECTM_OPENGL_LIBRARIES}
8691
libprojectM::API
8792
${PROJECTM_FILESYSTEM_LIBRARY}
8893
)
@@ -111,6 +116,7 @@ if(BUILD_SHARED_LIBS)
111116
PUBLIC
112117
${CMAKE_DL_LIBS}
113118
)
119+
114120
else()
115121
target_compile_definitions(projectM_main
116122
PUBLIC

src/libprojectM/MilkdropPreset/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ target_link_libraries(MilkdropPreset
138138
PUBLIC
139139
hlslparser
140140
GLM::GLM
141-
${PROJECTM_OPENGL_LIBRARIES}
142141
)
143142

144143
if(NOT BUILD_SHARED_LIBS)

src/libprojectM/ProjectMCWrapper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include "ProjectMCWrapper.hpp"
22

3+
#include <CrossGlLoader.hpp>
34
#include <projectM-4/projectM.h>
45

56
#include <Logging.hpp>
67

78
#include <Audio/AudioConstants.hpp>
89

10+
#include <SOIL2/soil2_gl_bridge.h>
11+
#include <SOIL2/SOIL2.h>
912
#include <cstring>
1013
#include <projectM-4/parameters.h>
1114
#include <projectM-4/render_opengl.h>
@@ -67,9 +70,17 @@ void projectm_free_string(const char* str)
6770
}
6871

6972
projectm_handle projectm_create()
73+
{
74+
return projectm_create_with_opengl_load_proc(nullptr, nullptr);
75+
}
76+
77+
projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data)
7078
{
7179
try
7280
{
81+
libprojectM::Renderer::CrossGlLoader::Instance().Initialize(load_proc, user_data);
82+
soil2_set_gl_resolver(&libprojectM::Renderer::CrossGlLoader::GladResolverThunk);
83+
SOIL_init();
7384
auto projectMInstance = new libprojectM::projectMWrapper();
7485
return reinterpret_cast<projectm_handle>(projectMInstance);
7586
}
@@ -83,6 +94,7 @@ void projectm_destroy(projectm_handle instance)
8394
{
8495
auto projectMInstance = handle_to_instance(instance);
8596
delete projectMInstance;
97+
libprojectM::Renderer::CrossGlLoader::Instance().Shutdown();
8698
}
8799

88100
void projectm_load_preset_file(projectm_handle instance, const char* filename,

src/libprojectM/Renderer/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ add_library(Renderer OBJECT
2222
Color.hpp
2323
CopyTexture.cpp
2424
CopyTexture.hpp
25+
CrossGlLoader.cpp
26+
CrossGlLoader.hpp
2527
FileScanner.cpp
2628
FileScanner.hpp
2729
Framebuffer.cpp
@@ -31,6 +33,7 @@ add_library(Renderer OBJECT
3133
Mesh.hpp
3234
MilkdropNoise.cpp
3335
MilkdropNoise.hpp
36+
PlatformLoader.h
3437
Point.hpp
3538
PresetTransition.cpp
3639
PresetTransition.hpp
@@ -75,6 +78,7 @@ target_link_libraries(Renderer
7578
GLM::GLM
7679
hlslparser
7780
SOIL2
81+
glad
7882
)
7983

8084
set_target_properties(Renderer PROPERTIES

0 commit comments

Comments
 (0)