### Add Executables for Getting Started Examples Source: https://github.com/mosra/magnum/blob/master/doc/snippets/CMakeLists.txt Configures two executables, 'getting-started' and 'getting-started-blue', for the basic Magnum application examples, linking against MagnumSdl2Application. These are added when MAGNUM_WITH_SDL2APPLICATION and MAGNUM_TARGET_GL are enabled. ```cmake add_executable(getting-started ${EXCLUDE_FROM_ALL_IF_TEST_TARGET} getting-started.cpp) add_executable(getting-started-blue ${EXCLUDE_FROM_ALL_IF_TEST_TARGET} getting-started-blue.cpp) target_link_libraries(getting-started PRIVATE MagnumSdl2Application) target_link_libraries(getting-started-blue PRIVATE MagnumSdl2Application) ``` -------------------------------- ### Skinning Shader Setup (GL) Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Example of compiling mesh data and setting up shaders for skinned mesh rendering, including uploading joint matrices. ```cpp #include #include #include #include #include #include void setupSkinning(Trade::MeshData& meshData, Trade::SkinData& skinData, GL::Mesh& mesh, GL::Buffer& jointMatrixBuffer) { // ... compile mesh and skin data ... GL::AbstractShaderProgram& shader = /* ... get shader ... */; shader.bindBuffer(GL::Buffer::Target::Uniform, jointMatrixBuffer); mesh.bindTo(shader); // ... set uniforms ... } ``` -------------------------------- ### Basic Application Setup with SDL2 Source: https://github.com/mosra/magnum/blob/master/doc/platform.dox Use this CMake snippet to find the SDL2 application module and link your executable against Magnum. Ensure SDL2 is installed on your system. ```cmake find_package(Magnum REQUIRED Sdl2Application) add_executable(myapplication MyApplication.cpp) target_link_libraries(myapplication Magnum::Magnum Magnum::Application) ``` -------------------------------- ### Multidraw Shader Setup (GL) Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Example of setting up shaders for multidraw calls in OpenGL. Uniform upload and binding are standard. ```cpp #include #include #include #include void setupMultidraw(GL::VertexArray& mesh, GL::Buffer& uniformBuffer, const Trade::MaterialData& material, const Matrix4& cameraMatrix, const Matrix4& transformationMatrix, const Color4& color) { // ... setup code ... GL::AbstractShaderProgram& shader = /* ... get shader ... */; shader.bindUniformBuffer(0, uniformBuffer); mesh.bindTo(shader); shader.setUniform("cameraMatrix", cameraMatrix); shader.setUniform("transformationMatrix", transformationMatrix); shader.setUniform("color", color); // ... draw call ... } ``` -------------------------------- ### Add Example to Documentation Source: https://github.com/mosra/magnum/blob/master/doc/developers.dox New examples must be listed in doc/building-examples.dox. ```doxygen \@subpage example-name "Example Name" ``` -------------------------------- ### Parsing URL Parameters as Command-Line Arguments Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox Demonstrates how command-line arguments are passed to the application using GET URL parameters in an HTML5 environment. The example shows the mapping from URL parameters to a C++ argument list. ```python ['--foo', 'bar', '--fizz', '--buzz', '3'] ``` -------------------------------- ### Document Example Source Files Source: https://github.com/mosra/magnum/blob/master/doc/developers.dox Reference all textual example sources using \@ref and set up navigation. ```doxygen - \@ref example-name/file.ext "file.ext" \@example example-name/file.ext \@m_examplenavigation{examples-example-name,example-name/} \@m_footernavigation ``` -------------------------------- ### Add New Example Documentation Page Source: https://github.com/mosra/magnum/blob/master/doc/developers.dox Create a new .dox file for the example, including brief description and navigation elements. ```doxygen \@brief A brief description of the example. \@m_footernavigation \@page example-name "Example Name" ``` -------------------------------- ### Reference Example Image in Documentation Source: https://github.com/mosra/magnum/blob/master/doc/developers.dox Include a scaled-down image for the example in its .dox file. ```doxygen \@image html example-name.png "Example Name" ``` -------------------------------- ### Example CMakeLists.txt Requirements Source: https://github.com/mosra/magnum/blob/master/doc/developers.dox Ensure the example's CMakeLists.txt includes essential CMake commands for standalone projects. ```cmake cmake_minimum_required(VERSION 3.10) project(ExampleName) # Add other CMake commands as needed ``` -------------------------------- ### 3D Projection and Transformation Uniforms (GLSL) Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Example demonstrating the use of generic shader-independent structures for projection and transformation parameters in GLSL. Ensure the buffer is bound to get default values; otherwise, rendering may fail. ```glsl #include #include layout(binding = 0) uniform Projection { mat4 matrix; } projection; layout(binding = 1) uniform Transformation { mat4 matrix; } transformation; void main() { gl_Position = projection.matrix * transformation.matrix * vec4(1.0); } ``` -------------------------------- ### Install MagnumAudio Library and Headers Source: https://github.com/mosra/magnum/blob/master/src/Magnum/Audio/CMakeLists.txt Installs the MagnumAudio library to the appropriate runtime, library, or archive destinations. It also installs the public headers. ```cmake install(TARGETS MagnumAudio RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumAudio_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Audio) ``` -------------------------------- ### Add Example CMake Option Source: https://github.com/mosra/magnum/blob/master/doc/developers.dox When adding a new example, ensure a corresponding CMake option is defined in the root CMakeLists.txt. ```cmake MAGNUM_WITH_EXAMPLENAME_EXAMPLE ``` -------------------------------- ### CMake Install Configuration for Emscripten Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox Configures the installation of an Emscripten application, including the HTML, JavaScript, WASM, and memory files. This example shows how to install a single application. ```cmake if(CORRADE_TARGET_EMSCRIPTEN) install(TARGETS my-application DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES my-application.html ${MAGNUM_WINDOWLESSEMSCRIPTENAPPLICATION_JS} ${MAGNUM_WEBAPPLICATION_CSS} DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/my-application.js.mem ${CMAKE_CURRENT_BINARY_DIR}/my-application.wasm DESTINATION ${CMAKE_INSTALL_PREFIX} OPTIONAL) endif() ``` -------------------------------- ### Install Magnum Library and Headers Source: https://github.com/mosra/magnum/blob/master/src/Magnum/CMakeLists.txt Installs the Magnum library targets (runtime, library, archive) and header files to their designated installation directories. ```cmake install(TARGETS Magnum RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${Magnum_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/configure.h ${CMAKE_CURRENT_BINARY_DIR}/version.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) ``` -------------------------------- ### Build and Install Gentoo Package Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Builds and installs the Magnum Gentoo development package from source. ```sh git clone https://github.com/mosra/magnum && cd magnum cd package/gentoo sudo ebuild dev-libs/magnum/magnum-9999.ebuild manifest clean merge ``` -------------------------------- ### Compile and Install Magnum Source: https://github.com/mosra/magnum/blob/master/doc/generated/README.md Steps to compile and install Magnum with specific plugins and utilities. Ensure Sdl2Application and necessary importers/converters are enabled. ```bash mkdir build-doc cd build-doc cmake ../doc/generated cmake --build . ``` -------------------------------- ### Platform-Specific Application Setup (CMake) Source: https://github.com/mosra/magnum/blob/master/doc/portability.dox Configure CMake to find the appropriate Magnum application library based on whether the target is OpenGL ES or desktop OpenGL. This example demonstrates conditional package finding and library linking. ```cmake find_package(Magnum REQUIRED) if(MAGNUM_TARGET_GLES) find_package(Magnum REQUIRED Sdl2Application) else() find_package(Magnum REQUIRED XEglApplication) endif() add_executable(myapplication MyApplication.cpp) target_link_libraries(myapplication Magnum::Magnum Magnum::Application) ``` -------------------------------- ### Generic Framebuffer Output Setup Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Sets up framebuffer outputs using generic definitions, equivalent to specific shader setups but more flexible. ```cpp #include #include #include void shaders_generic_object_id() { // ... setup shader and framebuffer ... // Generic setup for object ID output using ObjectShader = Magnum::Shaders::GenericGL; ObjectShader shader; // ... configure shader ... } ``` -------------------------------- ### Build and Install Magnum (Windows) Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Use these commands to build and install Magnum from the command line on Windows. Ensure you are in the build directory. ```bat mkdir build && cd build cmake -DCMAKE_INSTALL_PREFIX="C:/Sys" .. cmake --build . cmake --build . --target install ``` -------------------------------- ### Install all features of Magnum using Vcpkg Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs Magnum with all available features using the '*' wildcard in Vcpkg. ```bat vcpkg install magnum[*] ``` -------------------------------- ### Installing MagnumDebugTools Source: https://github.com/mosra/magnum/blob/master/src/Magnum/DebugTools/CMakeLists.txt Installs the MagnumDebugTools library and its headers to the appropriate directories based on Magnum's installation variables. This makes the library and its public headers available for use in other projects. ```cmake install(TARGETS MagnumDebugTools RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) ``` -------------------------------- ### Install Debian Packages Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs the built Magnum Debian packages using dpkg. ```sh sudo dpkg -i ../magnum*.deb ``` -------------------------------- ### Install MagnumFont Plugin Headers Source: https://github.com/mosra/magnum/blob/master/src/MagnumPlugins/MagnumFont/CMakeLists.txt Installs the MagnumFont header file and the generated configure.h header to the plugin's include directory. ```cmake install(FILES MagnumFont.h ${CMAKE_CURRENT_BINARY_DIR}/configure.h DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFont) ``` -------------------------------- ### SHADER_STORAGE_BUFFER_BINDING, SHADER_STORAGE_BUFFER_SIZE, SHADER_STORAGE_BUFFER_START Source: https://github.com/mosra/magnum/blob/master/doc/opengl-mapping.dox Shader storage buffer binding, size, and start. ```APIDOC ## SHADER_STORAGE_BUFFER_BINDING, SHADER_STORAGE_BUFFER_SIZE, SHADER_STORAGE_BUFFER_START ### Description Shader storage buffer binding, size, and start. ### Method Not queryable. ### Endpoint N/A ``` -------------------------------- ### Install Magnum using Homebrew Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs the latest stable version of Magnum with all its dependencies using Homebrew. ```sh brew install mosra/magnum/magnum ``` -------------------------------- ### Install SDL2 Development Libraries Source: https://github.com/mosra/magnum/blob/master/doc/getting-started.dox Commands to install the SDL2 development library on various Linux distributions and macOS using package managers. ```sh sudo pacman -S sdl2 # on ArchLinux sudo apt install libsdl2-dev # on Ubuntu / Debian brew install sdl2 # on macOS (via Homebrew) ``` -------------------------------- ### Install UWP/Windows RT Package Source: https://github.com/mosra/magnum/blob/master/doc/building.dox After building for UWP/Windows RT, use this command to install the package, making it available to dependent projects. ```bat cmake --build . --target install ``` -------------------------------- ### Vulkan Driver Workarounds Log Example Source: https://github.com/mosra/magnum/blob/master/doc/vulkan-workarounds.dox An example of how driver workarounds are listed in the engine startup log. These identifiers can be used to disable specific workarounds. ```shell Device: SwiftShader Device (LLVM 10.0.0) Device version: Vulkan 1.1 Enabled device extensions: VK_KHR_create_renderpass2 ... Using driver workarounds: swiftshader-image-copy-extent-instead-of-layers ... ``` -------------------------------- ### Installing Packages on Travis CI for Linux Source: https://github.com/mosra/magnum/blob/master/doc/platforms-linux.dox Use the `addons.apt.packages` directive in your `.travis.yml` to install necessary build tools and libraries. Check the `apt-package-whitelist` for available packages. ```yaml matrix: include: - language: cpp os: linux ... addons: apt: packages: - ninja-build - libsdl2-dev ... ``` -------------------------------- ### Install Magnum using Vcpkg Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs the latest stable version of Magnum with all its dependencies using Vcpkg. Ensure Vcpkg is set up and the default triplet is configured. ```bat vcpkg install magnum ``` -------------------------------- ### Get Instance Proc Addr Source: https://github.com/mosra/magnum/blob/master/doc/vulkan-mapping.dox Maps the Vulkan function `GetInstanceProcAddr` to the `Instance` constructor. ```APIDOC ## GetInstanceProcAddr ### Description Maps the Vulkan function `vkGetInstanceProcAddr` to the Magnum API `Instance` constructor. ### Method Not applicable (SDK function) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for the mapping. ### Request Example None ### Response None ``` -------------------------------- ### Texture Arrays in Multi-draw Setup Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Demonstrates a multi-draw setup where each draw uses a different texture array layer. This is useful for scenarios requiring distinct textures per draw call, especially in conjunction with uniform buffers. ```cpp #include #include #include #include #include #include #include #include #include #include "Abstract.h" using namespace Magnum; struct TextureArrays { /* ... */ GL::Mesh mesh; Shaders::PhongGL shader; GL::Buffer projectionBuffer, materialBuffer, lightBuffer, transformationBuffer; void setupMesh(GL::Texture2DArray& texture) { /* ... */ shader.bindTexture(texture); } void draw(const Matrix4& projection, const Matrix4& transformationMatrix, const PhongGL::MaterialData& material, const PhongGL::LightData& light, const std::vector& textureTransformationMatrices) { /* ... */ shader.setTransformationMatrix(transformationMatrix) .setMaterial(material) .setLight(light) .bindBuffer(Shaders::PhongGL::Uniform::Projection, projectionBuffer) .bindBuffer(Shaders::PhongGL::Uniform::Material, materialBuffer) .bindBuffer(Shaders::PhongGL::Uniform::Light, lightBuffer) .bindBuffer(Shaders::PhongGL::Uniform::TextureTransformation, transformationBuffer); /* ... */ mesh.draw(shader); } }; ``` -------------------------------- ### Install Magnum with specific features using Vcpkg Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs Magnum with specific features like glfwapplication and tgaimporter using Vcpkg's feature syntax. ```bat vcpkg install magnum[glfwapplication,tgaimporter] ``` -------------------------------- ### Default Installation Paths Source: https://github.com/mosra/magnum/blob/master/CMakeLists.txt Defines the default installation directories for various Magnum components, including binaries, libraries, data, CMake modules, and include files. ```cmake include(${CORRADE_LIB_SUFFIX_MODULE}) set(MAGNUM_BINARY_INSTALL_DIR bin) set(MAGNUM_LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}) set(MAGNUM_DATA_INSTALL_DIR share/magnum) set(MAGNUM_CMAKE_MODULE_INSTALL_DIR share/cmake/Magnum) set(MAGNUM_INCLUDE_INSTALL_DIR include/Magnum) set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR include/MagnumExternal) set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR include/MagnumPlugins) ``` -------------------------------- ### Instancing Shader Setup (GL) Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Demonstrates setting up shaders for instancing, rendering the same mesh multiple times with different transformations and materials. ```cpp #include #include #include #include void setupInstancing(GL::VertexArray& mesh, GL::Buffer& instanceBuffer, const Trade::MaterialData& material, const Matrix4& cameraMatrix, const std::vector>& instances) { // ... setup code ... GL::AbstractShaderProgram& shader = /* ... get shader ... */; shader.bindBuffer(GL::Buffer::Target::Uniform, instanceBuffer); mesh.bindTo(shader); shader.setUniform("cameraMatrix", cameraMatrix); // ... draw call for each instance ... } ``` -------------------------------- ### Travis CI: Download and Cache CMake Source: https://github.com/mosra/magnum/blob/master/doc/platforms-android.dox Install a specific CMake version on Travis CI for Android builds. This example downloads, extracts, and caches CMake to $HOME/cmake. ```yaml cache: directories: - $HOME/cmake install: - > if [ "$TARGET" == "android" ] && [ ! -e "$HOME/cmake/bin" ]; then cd $HOME ; wget https://cmake.org/files/v3.9/cmake-3.9.2-Linux-x86_64.tar.gz && mkdir -p cmake && cd cmake && tar --strip-components=1 -xzf ../cmake-3.9.2-Linux-x86_64.tar.gz && cd $TRAVIS_BUILD_DIR ; fi - > if [ "$TARGET" == "android" ]; then export PATH=$HOME/cmake/bin:$PATH && cmake --version ; fi ``` -------------------------------- ### Zero Initialization Source: https://github.com/mosra/magnum/blob/master/doc/types.dox Demonstrates the default zero-initialization for vectors, matrices, and range types, and how to explicitly use Math::ZeroInit. ```cpp using namespace Math; // Default zero-initialization Vector3 v; Matrix4 m; Range2Di r; // Explicit zero-initialization using tags Vector3 vZero = ZeroInit; Matrix4 mZero = ZeroInit.cast(); Range2Di rZero = ZeroInit; ``` -------------------------------- ### Use Ninja Bundled with Visual Studio Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox Example of how to use the Ninja generator bundled with Visual Studio for CMake builds on Windows. Adjust the path according to your Visual Studio installation. ```bat cmake -G Ninja -DCMAKE_MAKE_PROGRAM=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe ... ``` -------------------------------- ### Buffer Initialization in Desktop OpenGL (for comparison) Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox Shows a typical buffer initialization in desktop OpenGL, highlighting the contrast with the more explicit requirements of WebGL. ```cpp #include void initializeBuffer() { GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_DYNAMIC_DRAW); } ``` -------------------------------- ### Instantiate Plugin Manager and Load Plugin Source: https://github.com/mosra/magnum/blob/master/doc/plugins.dox Instantiate the plugin manager and then create plugin instances. The manager must outlive all plugin instances. ```cpp auto manager = Corrade::PluginManager::Manager::instance(); auto importer = manager->loadAndInstantiate("TgaImporter"); if (!importer) { /* Plugin loading failed */ return; } ``` -------------------------------- ### Configure Clang-CL with CMake Source: https://github.com/mosra/magnum/blob/master/doc/platforms-windows.dox Example of configuring CMake to use Clang-CL as a C/C++ compiler and LLD as a linker, with specific flags for 64-bit compilation. Note that manual path adjustments might be necessary for your specific Visual Studio installation. ```bat C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvarsall.bat" x64 cmake .. \ -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe" \ -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/clang-cl.exe" \ -DCMAKE_LINKER="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/bin/lld-link.exe" \ -DCMAKE_CXX_FLAGS="-m64" \ -G Ninja ``` -------------------------------- ### Install latest Git revision with Homebrew Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs the latest Git revision of Corrade and Magnum. Use this to upgrade existing installations. ```sh brew install --HEAD mosra/magnum/corrade brew install --HEAD mosra/magnum/magnum # If already installed, use the following to upgrade, in the same order brew upgrade --fetch-HEAD mosra/magnum/corrade brew upgrade --fetch-HEAD mosra/magnum/magnum ``` -------------------------------- ### Install Magnum on ArchLinux Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs the latest stable release of Magnum from the community repository. Ensure you have the Corrade ArchLinux package installed. ```sh sudo pacman -S magnum ``` -------------------------------- ### Manual Magnum Initialization with Custom Toolkit Source: https://github.com/mosra/magnum/blob/master/doc/platform.dox This C++ snippet illustrates manual Magnum initialization by first creating an OpenGL context and then an instance of `Platform::GLContext`. This approach is for advanced use cases or when not using the standard application wrappers. ```cpp #include #include int main(int argc, char** argv) { // 1. Initialize platform-specific OpenGL context (e.g., WGL, GLX, EGL) // Example for WGL (Windows): // HWND window = CreateWindow(...); // HDC deviceContext = GetDC(window); // HGLRC glContext = wglCreateContext(deviceContext); // wglMakeCurrent(deviceContext, glContext); // 2. Initialize Magnum Magnum::Platform::GLContext context(argc, argv); // ... rest of your application ... return 0; } ``` -------------------------------- ### Texture Configuration With Method Chaining Source: https://github.com/mosra/magnum/blob/master/doc/method-chaining.dox Demonstrates efficient texture configuration using method chaining, reducing redundant bindings and improving code clarity. ```cpp #define method-chaining-texture-chained \ Texture2D texture1, texture2, texture3; texture1.setStorage(1, PixelFormat::RGB8Unorm, {128, 128}) .setSwizzle(TextureComponents::RGB, {0, 1, 2}); texture2.setStorage(1, PixelFormat::RGB8Unorm, {128, 128}) .setSwizzle(TextureComponents::RGB, {0, 1, 2}); texture3.setStorage(1, PixelFormat::RGB8Unorm, {128, 128}) .setSwizzle(TextureComponents::RGB, {0, 1, 2}); ``` -------------------------------- ### Install Ninja on macOS with Homebrew Source: https://github.com/mosra/magnum/blob/master/doc/platforms-macos.dox Use this command to install Ninja on macOS. Setting HOMEBREW_NO_AUTO_UPDATE=1 can speed up the installation by skipping Homebrew's self-update. ```sh HOMEBREW_NO_AUTO_UPDATE=1 brew install ninja ``` -------------------------------- ### Configure and Render with PhongGL Shader (Classic Uniforms) Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Example configuration and rendering using Shaders::PhongGL with classic uniform setters. This approach is portable and works on older OpenGL ES and WebGL versions. It demonstrates setting transformation, projection, normal matrices, and colors. ```cpp phongShader .setTransformationProjectionMatrix(transformationProjection) .setNormalMatrix(transformation.rotationScaling()) // For non-uniform scaling .setLightPosition({1.0f, 1.0f, 1.0f}) .setLightColor(Color3::white()) .set albedo(Color3::blue()); mesh.draw(phongShader); ``` -------------------------------- ### CMake Installation for Emscripten Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox This CMake snippet installs the application targets, HTML, CSS, and JS files for Emscripten builds. It conditionally installs WASM and memory files if they exist. ```cmake if(CORRADE_TARGET_EMSCRIPTEN) install(TARGETS my-application DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES my-application.html ${MAGNUM_EMSCRIPTENAPPLICATION_JS} ${MAGNUM_WEBAPPLICATION_CSS} DESTINATION ${CMAKE_INSTALL_PREFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/my-application.js.mem ${CMAKE_CURRENT_BINARY_DIR}/my-application.wasm DESTINATION ${CMAKE_INSTALL_PREFIX} OPTIONAL) endif() ``` -------------------------------- ### Install magnum-al-info Source: https://github.com/mosra/magnum/blob/master/src/Magnum/Audio/CMakeLists.txt Installs the magnum-al-info executable to the specified directory if not targeting Emscripten. ```cmake if(NOT MAGNUM_TARGET_EMSCRIPTEN) install(TARGETS magnum-al-info DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) endif() ``` -------------------------------- ### Initializing Buffers in WebGL Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox Illustrates the required method for initializing buffers in WebGL, which differs from desktop OpenGL. This pattern ensures compatibility with WebGL's specific buffer binding requirements. ```cpp #include void initializeBuffer() { GLuint buffer; glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_DYNAMIC_DRAW); } ``` -------------------------------- ### Build and Install Magnum on Linux/Unix Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Build and install Magnum with SDL2 application support on Unix-like systems. Ensure dependencies are correctly located or specify CMAKE_PREFIX_PATH. 'sudo' may be needed for 'make install'. ```sh mkdir build && cd build cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr \ -DMAGNUM_WITH_SDL2APPLICATION=ON make make install # sudo may be needed ``` -------------------------------- ### Generic Vertex Attributes Setup Source: https://github.com/mosra/magnum/blob/master/doc/shaders.dox Illustrates setting up a mesh with generic vertex attributes that can be used with various compatible shaders. This approach promotes reusability of mesh data across different shader programs. ```cpp #include #include #include /* ... */ GL::Mesh mesh; // ... configure mesh with generic attributes ... // Example using PhongGL shader Shaders::PhongGL phongShader; // ... bind mesh to shader ... mesh.draw(phongShader); // Example using FlatGL3D shader (assuming same mesh configuration) Shaders::FlatGL3D flatShader; // ... bind mesh to shader ... mesh.draw(flatShader); ``` -------------------------------- ### Install RPM Build Dependencies Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs necessary dependencies for building RPM packages on Fedora. ```sh sudo dnf install fedora-packager rpmdevtools ``` -------------------------------- ### Install Emscripten via Homebrew Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox Use this command to install Emscripten on macOS using Homebrew. ```sh brew install emscripten ``` -------------------------------- ### Build Native Libraries for Multiple ABIs (ARM) Source: https://github.com/mosra/magnum/blob/master/doc/platforms-android.dox Create separate build directories and use CMake with specific CMAKE_ANDROID_ARCH_ABI and CMAKE_INSTALL_PREFIX for each ABI. This example builds for 32-bit and 64-bit ARM with SDK version 29. ```sh mkdir build-android-arm && cd build-android-arm cmake .. \ -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_SYSTEM_VERSION=29 \ -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \ -DCMAKE_ANDROID_STL_TYPE=c++_static \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr cmake --build . --target install cd .. mkdir build-android-arm64 && cd build-android-arm64 cmake .. \ -DCMAKE_SYSTEM_NAME=Android \ -DCMAKE_SYSTEM_VERSION=29 \ -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ -DCMAKE_ANDROID_STL_TYPE=c++_static \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr cmake --build . --target install ``` -------------------------------- ### Assemble and Install Debug Build Source: https://github.com/mosra/magnum/blob/master/doc/platforms-android.dox Use 'gradle assembleDebug' for a faster build that omits some checks, followed by 'gradle installDebug' to deploy the app to a connected device or emulator. ```sh gradle installDebug ``` -------------------------------- ### Handling Pointer Events in Windowed Applications Source: https://github.com/mosra/magnum/blob/master/doc/platform.dox Demonstrates how to handle generalized pointer input events, including mouse, touch, and pen. It shows how to check for primary touches and combine different pointer types for event handling. ```cpp void pointerPressEvent(Platform::Sdl2Application::PointerEvent& event) override { if (event.isPrimary()) { Debug{} << "Primary pointer pressed at " << event.position(); } if (event.buttons() & Platform::Sdl2Application::Pointer::Button::Left) { Debug{} << "Left button pressed"; } if (event.pointer() == Platform::Sdl2Application::Pointer::Finger) { Debug{} << "Finger pressed at " << event.position(); } if (event.pointer() & (Platform::Sdl2Application::Pointer::Left | Platform::Sdl2Application::Pointer::Right)) { Debug{} << "Left or Right button pressed"; } } void pointerMoveEvent(Platform::Sdl2Application::PointerEvent& event) override { if (event.isPrimary()) { Debug{} << "Primary pointer moved to " << event.position(); } } void pointerReleaseEvent(Platform::Sdl2Application::PointerEvent& event) override { if (event.isPrimary()) { Debug{} << "Primary pointer released at " << event.position(); } if (event.button() == Platform::Sdl2Application::Pointer::Button::Left) { Debug{} << "Left button released"; } } void scrollEvent(Platform::Sdl2Application::ScrollEvent& event) override { if (event.offset().y() > 0.0f) { Debug{} << "Scrolled down"; } else if (event.offset().y() < 0.0f) { Debug{} << "Scrolled up"; } if (event.offset().x() != 0.0f) { Debug{} << "Scrolled horizontally " << event.offset().x(); } } MAGNUM_SDL2APPLICATION_MAIN(My ونApplication) ``` -------------------------------- ### Install Arch Linux Package Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs a pre-built Magnum package on Arch Linux using pacman. ```sh sudo pacman -U magnum-*.pkg.tar.zst ``` -------------------------------- ### Custom Windowless Context Management Source: https://github.com/mosra/magnum/blob/master/doc/platform.dox Example demonstrating custom windowless context management. This approach is useful when integrating Magnum with custom platform toolkits or for specific context requirements. ```cpp #include #include int main(int argc, char** argv) { Corrade::Platform::WindowlessEglApplication application({argc, argv}); /* Make the context current and initialize Magnum */ Magnum::GL::Context glContext; // ... your code here ... return 0; } ``` -------------------------------- ### Install flextGL Header Source: https://github.com/mosra/magnum/blob/master/src/MagnumExternal/OpenGL/GL/CMakeLists.txt Installs the flextGL header file to the specified external include directory for OpenGL GL. ```cmake install(FILES flextGL.h DESTINATION ${MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR}/OpenGL/GL) ``` -------------------------------- ### Install MSYS2 Package Source: https://github.com/mosra/magnum/blob/master/doc/building.dox Installs the Magnum MSYS2 package using pacman. Choose either the 64-bit or 32-bit version. ```sh pacman -S mingw-w64-x86_64-magnum # or mingw-w64-i686-magnum ``` -------------------------------- ### Configure Windowed Application Source: https://github.com/mosra/magnum/blob/master/doc/platform.dox Customize application defaults, such as window size, by passing a Configuration instance to the constructor. Method chaining provides a convenient way to set these options. ```cpp Configuration conf; conf.setTitle("My Application") .setSize({800, 600}); MyApplication app(conf); ``` -------------------------------- ### Generate Gradle Wrapper Files Source: https://github.com/mosra/magnum/blob/master/doc/platforms-android.dox Execute this command on a system with Gradle installed to generate the gradlew scripts and directory for version control. ```shell gradle wrapper ``` -------------------------------- ### Create Static GLX Context Library Source: https://github.com/mosra/magnum/blob/master/src/Magnum/Platform/CMakeLists.txt Creates a static library for the GLX context, sets debug postfix, and configures position-independent code. ```cmake if(MAGNUM_WITH_GLXCONTEXT) if(NOT MAGNUM_TARGET_GL) message(SEND_ERROR "GlxContext is available only if MAGNUM_TARGET_GL is enabled") endif() add_library(MagnumGlxContext STATIC $) set_target_properties(MagnumGlxContext PROPERTIES DEBUG_POSTFIX "-d") if(NOT MAGNUM_BUILD_STATIC OR MAGNUM_BUILD_STATIC_PIC) set_target_properties(MagnumGlxContext PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() target_include_directories(MagnumGlxContext PUBLIC ${X11_INCLUDE_DIR}) target_link_libraries(MagnumGlxContext PUBLIC MagnumGL ${X11_LIBRARIES}) # If the GLVND library (CMake 3.11+) was found and linked to, we need # to link to GLX explicitly. Otherwise (and also on all systems except # Linux) the transitive dependency to classic GL lib from MagnumGL is # enough. Can't use OpenGL_OpenGL_FOUND, because that one is set also # if GLVND is *not* found. WTF. Also can't just check for # OPENGL_opengl_LIBRARY because that's set even if OpenGL_GL_PREFERENCE # is explicitly set to LEGACY. if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND) target_link_libraries(MagnumGlxContext PUBLIC OpenGL::GLX) endif() install(TARGETS MagnumGlxContext RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) # Magnum GlxContext target alias for superprojects add_library(Magnum::GlxContext ALIAS MagnumGlxContext) endif() ``` -------------------------------- ### Create a Windowless Application Source: https://github.com/mosra/magnum/blob/master/doc/platform.dox Implement the exec() function for windowless applications used for offscreen rendering or GPU tasks. The MAGNUM_WINDOWLESSEGLAPPLICATION_MAIN() macro simplifies usage and enhances portability. ```cpp #include #include class MyWindowlessApp : public Platform::WindowlessEglApplication { // ... public: explicit MyWindowlessApp(const Arguments& args): Platform::WindowlessEglApplication(args, Configuration{}) {} void exec() override { std::cout << "OpenGL version: " << GL::versionString() << std::endl; std::cout << "Renderer: " << GL::rendererString() << std::endl; } }; MAGNUM_WINDOWLESSAPPLICATION_MAIN(MyWindowlessApp) ``` -------------------------------- ### Configuring and Adding Scene Objects Source: https://github.com/mosra/magnum/blob/master/doc/method-chaining.dox Shows how method chaining can be used to configure and add objects to a scene without explicitly storing the object in a variable. ```cpp Scene3D scene; (*(new MyObject(&scene))) .rotateX(90.0_degf) .translate({-1.5f, 0.5f, 7.0f}); ``` -------------------------------- ### Install Magnum Shaders Library Source: https://github.com/mosra/magnum/blob/master/src/Magnum/Shaders/CMakeLists.txt Configures the installation of the MagnumShaders library, specifying runtime, library, and include directories based on CMake variables. ```cmake install(TARGETS MagnumShaders RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumShaders_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Shaders) ``` -------------------------------- ### Serving Emscripten Application Locally Source: https://github.com/mosra/magnum/blob/master/doc/platforms-html5.dox These commands demonstrate how to build and install an Emscripten application using CMake, then serve the deployed files using Python's built-in HTTP server for local testing. ```sh cd build-emscripten-wasm cmake -DCMAKE_INSTALL_PREFIX=/path/to/my/emscripten/deploy .. cmake --build . --target install cd /path/to/my/emscripten/deploy python -m http.server # or python -m SimpleHTTPServer with Python 2 ``` -------------------------------- ### Install GLFW Development Packages Source: https://github.com/mosra/magnum/blob/master/doc/getting-started.dox Commands to install GLFW development packages on Arch Linux, Ubuntu/Debian, and macOS. These are required for using GLFW with Magnum. ```sh sudo pacman -S glfw-x11 # on ArchLinux sudo apt install libglfw3-dev # on Ubuntu / Debian brew install glfw # on macOS (via Homebrew) ``` -------------------------------- ### Optimizing Device Property Retrieval (Single Expression) Source: https://github.com/mosra/magnum/blob/master/doc/vulkan-wrapping.dox When Vk::pickDevice, Vk::DeviceCreateInfo, and Vk::Device constructor are in a single expression, Vk::DeviceProperties is optimally moved and made available via Vk::Device::properties(). ```cpp auto instance = Vk::Instance{}; auto physicalDevice = Vk::pickDevice( instance, Vk::requiredInstanceExtensions()); // Vk::DeviceProperties is moved implicitly in this optimal case auto device = Vk::Device{ physicalDevice, Vk::requiredDeviceExtensions()}; // Access properties via Vk::Device::properties() auto& props = device.properties(); ``` -------------------------------- ### Change dylib Install Name with RPATH Source: https://github.com/mosra/magnum/blob/master/doc/platforms-macos.dox Modifies the install name of dynamic libraries to include an RPATH entry, ensuring the executable can find them within the bundle. ```sh install_name_tool -id "@rpath/libGLESv2.dylib" libGLESv2.dylib install_name_tool -id "@rpath/libEGL.dylib" libEGL.dylib ```