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.
sudo apt install corrade-dev magnum-dev magnum-plugins-devbrew install mosra/magnum/magnumDownload or build from source at https://github.com/mosra/magnum (CMake-based)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.
#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.
// Define vertex buffer, shader, and draw a triangle
// Uses Magnum::GL::Buffer, Magnum::Shaders::Flat, and Magnum::MeshMagnum provides modern abstractions for vertex buffers, shaders, and meshes, simplifying OpenGL rendering.
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.
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.
// Magnum provides ImGuiIntegration::Context for debug UIsEasily integrate Dear ImGui into Magnum apps for GUI overlays.
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.