Magnum

Language: CPP

Graphics/Game Development

Magnum was created to provide a modern, minimal, and modular alternative to large 3D engines like OGRE or Unity. It focuses on C++ developers who want direct control over the rendering pipeline but also appreciate high-level abstractions for graphics, math, and resource handling. With its modular design, Magnum can be used for game engines, VR/AR, embedded systems, and scientific visualization.

Magnum is a lightweight and modular C++11/C++14 graphics middleware for 2D and 3D graphics, game development, and visualization. It builds on top of modern OpenGL, Vulkan, and WebGPU APIs, offering a clean, extensible framework for rendering, math, input, and asset management.

Installation

linux: sudo apt install corrade-dev magnum-dev magnum-plugins-dev
mac: brew install mosra/magnum/magnum
windows: Download or build from source at https://github.com/mosra/magnum (CMake-based)

Usage

Magnum provides rendering backends (OpenGL, Vulkan), math utilities, a plugin-based asset system, input handling, and integrations with libraries like SDL2, GLFW, and ImGui. Developers can use only the modules they need thanks to its modular architecture.

Creating a window with OpenGL context

#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/Platform/Sdl2Application.h>

using namespace Magnum;

class MyApp: public Platform::Application {
    public:
        explicit MyApp(const Arguments& arguments): Platform::Application{arguments} {}

        void drawEvent() override {
            GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
            swapBuffers();
        }
};

MAGNUM_APPLICATION_MAIN(MyApp)

Creates a basic window with an OpenGL context using Magnum’s SDL2 platform integration.

Rendering a triangle

// Define vertex buffer, shader, and draw a triangle
// Uses Magnum::GL::Buffer, Magnum::Shaders::Flat, and Magnum::Mesh

Magnum provides modern abstractions for vertex buffers, shaders, and meshes, simplifying OpenGL rendering.

Loading textures via plugins

Trade::AnyImageImporter importer;
if(importer.openFile("texture.png")) {
    GL::Texture2D texture;
    texture.setStorage(1, GL::TextureFormat::RGBA8, importer.image2D(0)->size());
    texture.setSubImage(0, {}, *importer.image2D(0));
}

Loads an image using Magnum’s plugin system and uploads it to an OpenGL texture.

Using math utilities

Matrix4 transformation = Matrix4::translation({1.0f, 2.0f, 3.0f}) * Matrix4::scaling(Vector3{2.0f});

Magnum includes a fast and type-safe math library for transformations and linear algebra.

Integration with ImGui

// Magnum provides ImGuiIntegration::Context for debug UIs

Easily integrate Dear ImGui into Magnum apps for GUI overlays.

Error Handling

OpenGL context creation failure: Ensure proper GPU drivers are installed and platform integration (SDL2/GLFW) is configured correctly.
Plugin not found: Install Magnum plugins package or ensure plugins are in the correct runtime path.
Shader compilation errors: Verify GLSL versions and use Magnum’s shader classes for safer abstraction.

Best Practices

Use Magnum modules selectively; don’t include everything if you only need math or asset loaders.

Prefer Magnum’s math library over raw OpenGL math handling for safety and clarity.

Use plugins for image, audio, and model loading instead of writing custom parsers.

Leverage Vulkan backend for modern rendering pipelines when possible.

Integrate with SDL2 or GLFW for platform and input management.