Cube Map
Demonstrates usage of cube map textures and texture blending.
Simulates open world with two tarnish reflective spheres in front of the camera. This example also demonstrates usage of scene graph, resource manager and pre-made primitives.
Usage
The application tries to load a cube map texture from the directory in which it is run, implicitly six JEPG files +x.jpg
, -x.jpg
, +y.jpg
, -y.jpg
, +z.jpg
and -z.jpg
, each representing one side of the cube. Note that all images must be turned upside down (+Y is top):
+----+ | -Y | +----+----+----+----+ | -Z | -X | +Z | +X | +----+----+----+----+ | +Y | +----+
You can also pass a path to the application as a parameter:
./magnum-cubemap ~/images/city
The application will then load ~/images/city+x.jpg
, ~/images/city-x.jpg
etc. as a cube map texture. Alternatively, if you have a combined cube map file (such as an EXR), you can load it directly:
./magnum-cubemap path/to/a/cubemap/file.exr
Sample cube map files are supplied alongside the source. If you install the examples, the images are also copied into <prefix>/share/magnum/examples/cubemap/
. Running the example with the bundled files can be then done like this:
./magnum-cubemap <path-to-example-source>/
Key controls
Arrow keys rotate the camera around the spheres. It is not possible, due to nature of the cube map projection, to move around the scene.
Credits
The sample images provided in this example are work of Emil Persson, aka Humus — http:/
Source
Full source code is linked below and together with assets available in the magnum-examples GitHub repository. This example depends on either the JpegImporter, StbImageImporter or any other plugin providing JPEG loading. These are not a part of the core Magnum repository, see their documentation for usage instructions.
- CMakeLists.txt
- configure.h.cmake
- CubeMap.cpp
- CubeMap.h
- CubeMapExample.cpp
- CubeMapShader.cpp
- CubeMapShader.frag
- CubeMapShader.h
- CubeMapShader.ver
- Reflector.cpp
- Reflector.h
- ReflectorShader.cpp
- ReflectorShader.frag
- ReflectorShader.h
- ReflectorShader.vert
- resources.conf
- Types.cpp
- Types.h
The ports branch contains additional patches for iOS support that aren't present in master
in order to keep the example code as simple as possible.