Getting started » Downloading and building examples

Guide how to download and build examples for the Magnum engine.

Examples demonstrate Magnum features, usage and capabilities. They are not needed for essential usage, but are useful for learning purposes in addition to the documentation itself.

Prepared packages

The easiest way to install Magnum Examples is to use one of the ready-made packages for your platform of choice. See Manual build if you want to have more control. Cross-compiling is very similar to cross-compiling of Magnum itself.

ArchLinux packages

In package/archlinux/magnum-examples-git there is a package for Git development build. The package is also in AUR as The package is also in AUR as magnum-examples-git. It depends on Corrade, Magnum, Magnum Plugins, Magnum Integration and Magnum Extras ArchLinux packages.

There are also quite a few development packages for native builds or cross-compilation for Emscripten, Android and MinGW. See the PKGBUILD files in the package/archlinux directory. They allow you to build and install the package directly from the source tree. Example usage:

git clone git://github.com/mosra/magnum-examples && cd magnum-examples
cd package/archlinux
makepkg -fp PKGBUILD # or any other PKGBUILD file

Once built, install the package using pacman:

sudo pacman -U magnum-examples-*.pkg.tar.xz

Edit the PKGBUILDs if you want to pass additional flags to CMake or enable / disable additional features.

Packages for Debian, Ubuntu and derivatives

The package/debian/ directory contains all files needed for building Debian packages. You need Corrade, Magnum, Magnum Plugins, Magnum Integration and Magnum Extras Debian packages installed and in addition also the dpkg-dev and debhelper packages. Building is easy, just change directory to package root, link or copy the package/debian directory there and run dpkg-buildpackage:

git clone git://github.com/mosra/magnum-examples && cd magnum-examples
ln -s package/debian .
dpkg-buildpackage

This will compile binary and development packages, which will then appear in a parent directory. Install them using dpkg:

sudo dpkg -i ../magnum-examples*.deb

If you want to pass additional flags to CMake or enable / disable additional features, add them to dh_auto_configure at the bottom of debian/rules. Watch out, as indentation has to be done using tabs, not spaces.

Gentoo Linux ebuilds

Gentoo Git ebuild is available in the package/gentoo directory. Get the Corrade, Magnum, Magnum Plugins, Magnum Integration and Magnum Extras Gentoo packages first and then build and install Magnum Examples like this:

git clone git://github.com/mosra/magnum-examples && cd magnum-examples
cd package/gentoo
sudo ebuild dev-libs/magnum-examples/magnum-examples-99999.ebuild manifest clean merge

If you want to pass additional flags to CMake or enable / disable additional features, add them to mycmakeargs in the *.ebuild file.

Homebrew formulas for macOS

macOS Homebrew formulas building the latest Git revision are in the package/homebrew directory. Either use the *.rb files directly or use the tap at https://github.com/mosra/homebrew-magnum. This will install the latest stable version of Magnum Examples with all dependencies:

brew install mosra/magnum/magnum-examples

But often you may want to install the latest Git revision of all Magnum projects instead:

brew install --HEAD mosra/magnum/corrade
brew install --HEAD mosra/magnum/magnum
brew install --HEAD mosra/magnum/magnum-plugins
brew install --HEAD mosra/magnum/magnum-integration
brew install --HEAD mosra/magnum/magnum-extras
brew install --HEAD mosra/magnum/magnum-examples

When installing from the *.rb files you need to install the Corrade, Magnum, Magnum Plugins, Magnum Integration and Magnum Extras Homebrew packages first. If you want to pass additional flags to CMake or enable / disable additional features, edit the *.rb file.

Manual build

The source is available on GitHub: https://github.com/mosra/magnum-examples. Building the examples is very similar to building Magnum itself. See Downloading and building for additonal information about building, cross-compiling and platform-specific issues. Unlike other Magnum repositories, ports to mobile and web platforms are provided in the ports branch and not present in master in order to keep the example code as simple as possible.

Enabling or disabling features

By default only the Triangle example is built. All examples depend on various libraries from the core Magnum repository and the Platform::Sdl2Application class, unless said otherwise Some examples depend on plugins, extras and integration libraries, see Downloading and building plugins, Downloading and building integration libraries and Downloading and building extras for more information.

Besides building the whole project and enabling a particular subset of examples, it's also possible to build each example as if the example itself would be a project root. For example:

cd magnum-examples
mkdir build-cubemap && cd build-cubemap
cmake ../src/cubemap
# ...

Building documentation

The documentation for examples is built as part of of the main Magnum documentation. Clone the projects next to each other and continue as described in Building documentation.

Continuous Integration

Travis

In package/ci/ there is a travis.yml file with Linux GCC 4.7, macOS, Linux desktop GLES2/GLES3, iOS GLES2/GLES3, Emscripten WebGL1/WebGL2 and Android GLES2/GLES3 configuration. Online at https://travis-ci.org/mosra/magnum-examples.

AppVeyor

In package/ci/ there is an appveyor.yml file with Windows desktop MSVC, MinGW, Windows desktop GLES2/GLES3 and Windows RT GLES2/GLES3 configuration. Online at https://ci.appveyor.com/project/mosra/magnum-examples.