Examples

Learn by example to get quickly up to speed.

The examples assume that you have at least basic knowledge about graphics (what are homogeneous coordinates, what is mesh, vertex, texture...), how GPU APIs work (what are buffers, what is depth test for...) and basics of GLSL (attributes, uniforms, vertex/fragment shaders...). Deep knowledge of OpenGL / Vulkan APIs themselves is not required, as Magnum wraps most of the functionality in its own classes.

Full source code for all examples is available in the GitHub repository, see Downloading and building examples for more information. The ports branch contains additional patches for mobile and web platform support that aren't present in master in order to keep the example code as simple as possible.

Fully documented tutorials

The following examples explain the basic principles and have fully documented tutorials:

Image Your First Triangle live web demo
Basic rendering with builtin shaders.
Image Textured Quad live web demo
Indexed meshes, importing image data, texturing and custom shaders.
Image Primitives live web demo
Importing mesh data, 3D transformations and input handling.
Image Model Viewer live web demo
Scene graph, resource management and model importing.
Image Triangle using plain GLFW
Shows how to use Magnum with custom platform integration APIs.
Image Triangle using sokol_gfx
Shows how to use custom renderers with Magnum.

Other examples

The following consist of documented source code only:

Image Area Lights ui live web demo
Basic real-time area lights.
Image Audio sound live web demo
Shows how to play spatialized audio with Magnum.
Image Leap Motion vr
Integration of the LeapMotion SDK into Magnum.
Image Bullet Physics physics live web demo
Integration of Bullet Physics into Magnum.
Image DART Physics physics
Integration of DART Physics into Magnum.
Image Box2D physics live web demo
A simple example using the Box2D physics library.
Image 2D Fluid Simulation physics live web demo
2D fluid simulation using the APIC method.
Image 3D Fluid Simulation physics live web demo
SPH fluid simulation with a dynamic boundary.
Image Ray Tracing live web demo
Simple iterative CPU ray tracing.
Image Octree live web demo
Loose octree for accelerating collision detection.
Image ArcBall Camera live web demo
Intuitive camera control with smooth navigation.
Image Mouse Interaction live web demo
Advanced depth-aware mouse interaction for navigating a scene.
Image ImGui ui live web demo
Integration of Dear ImGui into Magnum.
Image Animated GIF animation
Playing back an animated GIF. On the GPU or in a terminal.
Image Motion blur
Accumulates multiple frames together to create a motion blur effect.
Image Cube Map
Demonstrates usage of cube map textures and texture blending.
Image Shadow map
Showcases the Parallel Split / Cascade shadow mapping technique.
Image Object Picking live web demo
Usage of multiple framebuffer attachments to implement object picking.
Image Text rendering live web demo
Showcase of Magnum distance-field text rendering.
Image Triangle using Vulkan vulkan
Using Vulkan with SPIR-V assembly to produce a triangle offscreen.
Image Textured triangle using Vulkan vulkan
Showcases Vulkan descriptor sets and SPIR-V assembly.
Image Oculus VR vr
Integration of the Oculus SDK into Magnum.
Image WebXR vr live web demo
Basic WebXR application.

There are also examples for the Corrade library itself.

While Magnum itself and its documentation is licensed under the MIT/Expat license, all example code is put into public domain (or UNLICENSE) to free you from any legal obstacles when reusing the code in your apps:

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/