Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BUILDING-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,6 @@ else()
message(STATUS "Building for OpenGL Core Profile")
find_package(OpenGL REQUIRED)
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL)
# GLX is required by SOIL2 on platforms with the X Window System (e.g. most Linux distributions)
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()

Expand Down
3 changes: 0 additions & 3 deletions docs/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ Only relevant for Windows:
library dependencies and/or using CMake to configure the build.
- `NuGet <https://www.nuget.org/>`__: Dependency manager for .NET.
Required to build the EyeTune app.
- `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
---------------------------
Expand Down
14 changes: 14 additions & 0 deletions src/api/include/projectM-4/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
14 changes: 13 additions & 1 deletion src/libprojectM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ add_compile_definitions(
$<IF:$<PLATFORM_ID:Windows>,STBI_NO_DDS,>
)

include_directories(
"${PROJECTM_SOURCE_DIR}/vendor/glad/include"
)

add_subdirectory(Audio)
add_subdirectory(MilkdropPreset)
add_subdirectory(Renderer)
add_subdirectory(UserSprites)

set(PROJECTM_LINK_GL_LIBS "")
if (WIN32)
# windows libs need to link to opengl32.dll
set(PROJECTM_LINK_GL_LIBS "${PROJECTM_OPENGL_LIBRARIES}")
endif()

add_library(projectM_main OBJECT
"${PROJECTM_EXPORT_HEADER}"
Logging.cpp
Expand Down Expand Up @@ -70,6 +80,7 @@ add_library(projectM
$<TARGET_OBJECTS:SOIL2>
$<TARGET_OBJECTS:projectM_main>
$<TARGET_OBJECTS:projectM::Eval>
$<TARGET_OBJECTS:glad_obj>
)

target_include_directories(projectM
Expand All @@ -79,9 +90,9 @@ target_include_directories(projectM

target_link_libraries(projectM
PUBLIC
${PROJECTM_OPENGL_LIBRARIES}
libprojectM::API
${PROJECTM_FILESYSTEM_LIBRARY}
${PROJECTM_LINK_GL_LIBS}
)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand All @@ -107,6 +118,7 @@ if(BUILD_SHARED_LIBS)
target_link_libraries(projectM
PUBLIC
${CMAKE_DL_LIBS}
${PROJECTM_LINK_GL_LIBS}
)
else()
target_compile_definitions(projectM_main
Expand Down
1 change: 0 additions & 1 deletion src/libprojectM/MilkdropPreset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ target_link_libraries(MilkdropPreset
PUBLIC
hlslparser
GLM::GLM
${PROJECTM_OPENGL_LIBRARIES}
)

if(NOT BUILD_SHARED_LIBS)
Expand Down
24 changes: 23 additions & 1 deletion src/libprojectM/ProjectMCWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include <Audio/AudioConstants.hpp>

#include <Renderer/CrossGlLoader.hpp>
#include <SOIL2/soil2_gl_bridge.h>
#include <SOIL2/SOIL2.h>

#include <projectM-4/parameters.h>
#include <projectM-4/render_opengl.h>

Expand Down Expand Up @@ -67,10 +71,27 @@ void projectm_free_string(const char* str)
}

projectm_handle projectm_create()
{
return projectm_create_with_opengl_load_proc(nullptr, nullptr);
}

projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data)
{
try
{
auto projectMInstance = new libprojectM::projectMWrapper();
// invoke loader to discover gl function pointer and init glad
auto success = libprojectM::Renderer::CrossGlLoader::Instance().Initialize(load_proc, user_data);
if (!success)
{
return nullptr;
}

// init SOIL2 gl functions
soil2_set_gl_resolver(&libprojectM::Renderer::CrossGlLoader::GladResolverThunk);
SOIL_init();

// create projectM
auto* projectMInstance = new libprojectM::projectMWrapper();
return reinterpret_cast<projectm_handle>(projectMInstance);
}
catch (...)
Expand All @@ -83,6 +104,7 @@ void projectm_destroy(projectm_handle instance)
{
auto projectMInstance = handle_to_instance(instance);
delete projectMInstance;
libprojectM::Renderer::CrossGlLoader::Instance().Shutdown();
}

void projectm_load_preset_file(projectm_handle instance, const char* filename,
Expand Down
4 changes: 4 additions & 0 deletions src/libprojectM/Renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ add_library(Renderer OBJECT
Color.hpp
CopyTexture.cpp
CopyTexture.hpp
CrossGlLoader.cpp
CrossGlLoader.hpp
FileScanner.cpp
FileScanner.hpp
Framebuffer.cpp
Expand All @@ -32,6 +34,7 @@ add_library(Renderer OBJECT
MilkdropNoise.cpp
MilkdropNoise.hpp
OpenGL.h
PlatformLoader.h
Point.hpp
PresetTransition.cpp
PresetTransition.hpp
Expand Down Expand Up @@ -76,6 +79,7 @@ target_link_libraries(Renderer
GLM::GLM
hlslparser
SOIL2
glad
)

set_target_properties(Renderer PROPERTIES
Expand Down
Loading
Loading