├── GridRenderer.cpp ├── GridRenderer.h ├── GridRenderer.png ├── LICENSE ├── LineRenderer.cpp ├── LineRenderer.gif ├── LineRenderer.h ├── MathUtils.cpp ├── MathUtils.h ├── README.md ├── ThirdPersonCameraController.cpp ├── ThirdPersonCameraController.gif ├── ThirdPersonCameraController.h ├── TranslateController.cpp ├── TranslateController.gif ├── TranslateController.h ├── Types.h └── demo ├── .gitignore ├── CMakeLists.txt ├── README.md ├── modules ├── FindCorrade.cmake ├── FindMagnum.cmake └── FindSDL2.cmake └── src ├── CMakeLists.txt ├── CubeDrawable.h └── MyApplication.cpp /GridRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "GridRenderer.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace Magnum; 7 | 8 | Color3 getLineColor(Float i, const Color3 &baseColor, const Color3 &axesColor, const Color3 &subColor); 9 | 10 | Color3 getLineColor(Float i, const Color3 &baseColor, const Color3 &axesColor, const Color3 &subColor) { 11 | if (i == 0) { 12 | return axesColor; 13 | } 14 | 15 | if (std::fmod(i, 5) == 0) { 16 | return subColor; 17 | } 18 | 19 | return baseColor; 20 | } 21 | 22 | GridRenderer::GridRenderer(Object3D& object, Magnum::SceneGraph::DrawableGroup3D* drawables) : SceneGraph::Drawable3D{object, drawables} { 23 | _shader = DebugTools::ResourceManager::instance().get("VertexColorShader3D"); 24 | if(!_shader) DebugTools::ResourceManager::instance().set(_shader.key(), new Shaders::VertexColor3D); 25 | 26 | _mesh = DebugTools::ResourceManager::instance().get("grid"); 27 | if(_mesh) return; 28 | 29 | GL::Buffer vertexBuffer{GL::Buffer::TargetHint::Array}; 30 | GL::Mesh* mesh = new GL::Mesh; 31 | 32 | struct Vertex { 33 | Vector3 position; 34 | Color3 color; 35 | }; 36 | 37 | std::vector data; 38 | 39 | Float size = 10; 40 | Float brightness = 0.3f; 41 | 42 | Color3 baseColor(brightness); 43 | Color3 subColor(brightness * 1.5f); 44 | Color3 xColor{ brightness * 2.f, brightness, brightness }; 45 | Color3 zColor{ brightness, brightness, brightness * 2.f }; 46 | 47 | for (Float i = -size; i <= size; ++i) { 48 | data.push_back({ { -size, 0, i }, getLineColor(i, baseColor, xColor, subColor) }); 49 | data.push_back({ { size, 0, i }, getLineColor(i, baseColor, xColor, subColor) }); 50 | 51 | data.push_back({ { i, 0, -size }, getLineColor(i, baseColor, zColor, subColor) }); 52 | data.push_back({ { i, 0, size }, getLineColor(i, baseColor, zColor, subColor) }); 53 | } 54 | 55 | vertexBuffer.setData(data, GL::BufferUsage::StaticDraw); 56 | 57 | mesh->setPrimitive(GL::MeshPrimitive::Lines) 58 | .setCount(data.size()) 59 | .addVertexBuffer(std::move(vertexBuffer), 0, Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Color3{}); 60 | 61 | DebugTools::ResourceManager::instance().set(_mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); 62 | } 63 | 64 | void GridRenderer::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) { 65 | _shader->setTransformationProjectionMatrix(camera.projectionMatrix() * transformationMatrix); 66 | _mesh->draw(*_shader); 67 | } 68 | -------------------------------------------------------------------------------- /GridRenderer.h: -------------------------------------------------------------------------------- 1 | #ifndef GridRenderer_h 2 | #define GridRenderer_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "Types.h" 11 | 12 | class GridRenderer: public Magnum::SceneGraph::Drawable3D { 13 | public: 14 | explicit GridRenderer(Object3D& object, Magnum::SceneGraph::DrawableGroup3D* drawables = nullptr); 15 | 16 | private: 17 | void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; 18 | 19 | Magnum::Resource _shader; 20 | Magnum::Resource _mesh; 21 | Magnum::Resource _vertexBuffer; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /GridRenderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexesDev/magnum-tips/8a2e94809075d7d598110edf66b69f6f23335773/GridRenderer.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of 8 | this software dedicate any and all copyright interest in the software to 9 | the public domain. We make this dedication for the benefit of the public 10 | at large and to the detriment of our heirs and successors. We intend this 11 | dedication to be an overt act of relinquishment in perpetuity of all 12 | present and future rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | 21 | For more information, please refer to 22 | -------------------------------------------------------------------------------- /LineRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "LineRenderer.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace Magnum; 7 | 8 | constexpr std::array positions{{ 9 | { 0, 0, 0 }, 10 | { 0, 0, 1.f } 11 | }}; 12 | 13 | LineRenderer::LineRenderer(Object3D& object, Magnum::SceneGraph::DrawableGroup3D* drawables) : SceneGraph::Drawable3D{object, drawables} { 14 | _shader = DebugTools::ResourceManager::instance().get("FlatShader3D"); 15 | if(!_shader) DebugTools::ResourceManager::instance().set(_shader.key(), new Shaders::Flat3D); 16 | 17 | _mesh = DebugTools::ResourceManager::instance().get("my-line"); 18 | if(_mesh) return; 19 | 20 | GL::Mesh* mesh = new GL::Mesh; 21 | 22 | GL::Buffer vertexBuffer{GL::Buffer::TargetHint::Array}; 23 | vertexBuffer.setData(positions, GL::BufferUsage::StaticDraw); 24 | 25 | mesh->setPrimitive(GL::MeshPrimitive::Lines) 26 | .setCount(2) 27 | .addVertexBuffer(std::move(vertexBuffer), 0, Shaders::Flat3D::Position{}); 28 | 29 | DebugTools::ResourceManager::instance().set(_mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); 30 | } 31 | 32 | void LineRenderer::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) { 33 | for (auto &line : _lines) { 34 | _shader->setTransformationProjectionMatrix(camera.projectionMatrix() * transformationMatrix * line->transformation()) 35 | .setColor(line->color()); 36 | 37 | _mesh->draw(*_shader); 38 | } 39 | } 40 | 41 | Matrix4 LineRendererOptions::transformation() { 42 | if (_dirty) { 43 | Float len = (_to - _from).length(); 44 | 45 | Vector3 start = Vector3::zAxis(1); 46 | Vector3 dir = (_to - _from).normalized(); 47 | 48 | Vector3 right = Math::cross(start, dir).normalized(); 49 | Rad angle = Math::angle(start, dir); 50 | 51 | _transformation = Matrix4::translation(_from) * Matrix4::rotation(angle, right) * Matrix4::scaling(Vector3(len)); 52 | _dirty = false; 53 | } 54 | 55 | return _transformation; 56 | } 57 | -------------------------------------------------------------------------------- /LineRenderer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexesDev/magnum-tips/8a2e94809075d7d598110edf66b69f6f23335773/LineRenderer.gif -------------------------------------------------------------------------------- /LineRenderer.h: -------------------------------------------------------------------------------- 1 | #ifndef LineRenderer_h 2 | #define LineRenderer_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "Types.h" 12 | 13 | class LineRendererOptions { 14 | public: 15 | explicit LineRendererOptions(const Magnum::Vector3 &from, const Magnum::Vector3 &to, const Magnum::Color3 color) : 16 | _from(from), _to(to), _color(color) {} 17 | 18 | Magnum::Vector3 color() const { 19 | return _color; 20 | } 21 | 22 | LineRendererOptions &setTo(const Magnum::Vector3& to) { 23 | _to = to; 24 | _dirty = true; 25 | return *this; 26 | } 27 | 28 | LineRendererOptions &setFrom(const Magnum::Vector3& from) { 29 | _from = from; 30 | _dirty = true; 31 | return *this; 32 | } 33 | 34 | LineRendererOptions &setColor(const Magnum::Color3& color) { 35 | _color = color; 36 | return *this; 37 | } 38 | 39 | Magnum::Matrix4 transformation(); 40 | 41 | protected: 42 | Magnum::Vector3 _from; 43 | Magnum::Vector3 _to; 44 | Magnum::Matrix4 _transformation; 45 | Magnum::Color3 _color; 46 | bool _dirty = true; 47 | }; 48 | 49 | class LineRenderer: public Magnum::SceneGraph::Drawable3D { 50 | public: 51 | explicit LineRenderer(Object3D& object, Magnum::SceneGraph::DrawableGroup3D* drawables = nullptr); 52 | 53 | LineRendererOptions* add(const Magnum::Vector3 &from, const Magnum::Vector3 &to, const Magnum::Color3 color = Magnum::Color3(1)) { 54 | LineRendererOptions *line = new LineRendererOptions(from, to, color); 55 | _lines.push_back(Corrade::Containers::Pointer(line)); 56 | return line; 57 | } 58 | 59 | private: 60 | void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; 61 | 62 | Magnum::Resource _shader; 63 | Magnum::Resource _mesh; 64 | Magnum::Resource _vertexBuffer; 65 | 66 | std::vector> _lines; 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /MathUtils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MathUtils.h" 3 | 4 | using namespace Magnum; 5 | 6 | Ray getCameraToViewportRay(SceneGraph::Camera3D& camera, const Vector2& screenPoint) { 7 | Matrix4 inverseVP = (camera.projectionMatrix() * camera.cameraMatrix()).inverted(); 8 | 9 | Float nx = (2.0f * screenPoint.x()) - 1.0f; 10 | Float ny = 1.0f - (2.0f * screenPoint.y()); 11 | 12 | Vector3 nearPoint(nx, ny, -1.f); 13 | Vector3 midPoint (nx, ny, 0.0f); 14 | 15 | Vector3 rayOrigin = inverseVP.transformPoint(nearPoint); 16 | Vector3 rayTarget = inverseVP.transformPoint(midPoint); 17 | Vector3 rayDirection = (rayTarget - rayOrigin).normalized(); 18 | 19 | return { rayOrigin, rayDirection }; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /MathUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef MathUtils_h 2 | #define MathUtils_h 3 | 4 | #include 5 | 6 | struct Ray { 7 | Magnum::Vector3 origin; 8 | Magnum::Vector3 direction; 9 | }; 10 | 11 | Ray getCameraToViewportRay(Magnum::SceneGraph::Camera3D& camera, const Magnum::Vector2& screenPoint); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magnum tips 2 | 3 | ### TranslateController 4 | 5 | ```cpp 6 | _translateController = new TranslateController{&_scene, &_debugDrawables}; 7 | 8 | // controller only works if it has children 9 | Object3D *cube = new Object3D{_translateController}; 10 | new CubeDrawable{*_cube, &_drawables}; 11 | 12 | // disable controller 13 | cube->setParent(&_scene); 14 | 15 | // handle mouse events 16 | void MyApplication::mouseMoveEvent(MouseMoveEvent& event) { 17 | Vector2 screenPoint = Vector2{event.position()} / Vector2{windowSize()}; 18 | Ray cameraRay = getCameraToViewportRay(*_camera, screenPoint); 19 | 20 | _translateController->move(cameraRay); 21 | } 22 | 23 | void MyApplication::mousePressEvent(MouseEvent& event) { 24 | if (event.button() == MouseEvent::Button::Left) { 25 | Vector2 screenPoint = Vector2{event.position()} / Vector2{windowSize()}; 26 | Ray cameraRay = getCameraToViewportRay(*_camera, screenPoint); 27 | 28 | _translateController->grab(cameraRay); 29 | } 30 | } 31 | 32 | void MyApplication::mouseReleaseEvent(MouseEvent& event) { 33 | if (event.button() == MouseEvent::Button::Left) { 34 | _translateController->release(); 35 | } 36 | } 37 | ``` 38 | 39 | ![TranslateController](https://raw.githubusercontent.com/alexesDev/magnum-tips/master/TranslateController.gif) 40 | 41 | ### LineRenderer 42 | 43 | ```cpp 44 | _lineRenderer = new LineRenderer{_scene, &_debugDrawables}; 45 | 46 | // static lines (from, to, color) 47 | _lineRenderer->add({ 0, 0, 0 }, { 1, 1, 1 }, { 1, 0, 0 }); 48 | _lineRenderer->add({ -1, 2, 0 }, { 1, 1, 1 }, { 0, 1, 0 }); 49 | 50 | // dynamic line 51 | auto line = _lineRenderer->add({ 0, 0, 0 }, { 1, 1, 1 }); 52 | line->setTo({ -1, 2, 0 }); 53 | ``` 54 | 55 | ![LineRenderer](https://raw.githubusercontent.com/alexesDev/magnum-tips/master/LineRenderer.gif) 56 | 57 | ### ThirdPersonCameraController 58 | 59 | ```cpp 60 | _cameraController = new ThirdPersonCameraController{_scene}; 61 | _cameraController->camera() 62 | .setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend) 63 | .setProjectionMatrix(Matrix4::perspectiveProjection(Deg(60.0f), 4.0f/3.0f, 0.01f, 200.0f)) 64 | .setViewport(GL::defaultFramebuffer.viewport().size()); 65 | 66 | // ... 67 | 68 | _cameraController->translate({ 5, 0, 0 }); 69 | 70 | // ... 71 | 72 | void MyApplication::drawEvent() { 73 | GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth); 74 | 75 | _cameraController->camera().draw(_drawables); 76 | 77 | // ... 78 | } 79 | 80 | void MyApplication::mouseMoveEvent(MouseMoveEvent& event) { 81 | if (event.buttons() == MouseMoveEvent::Button::Left) { 82 | _cameraController->move(event.relativePosition()); 83 | } 84 | } 85 | ``` 86 | 87 | ![ThirdPersonCameraController](https://raw.githubusercontent.com/alexesDev/magnum-tips/master/ThirdPersonCameraController.gif) 88 | 89 | ### GridRenderer 90 | 91 | ```cpp 92 | DebugTools::ResourceManager _debugManager; 93 | SceneGraph::DrawableGroup3D _debugDrawables; 94 | 95 | Scene3D _scene; 96 | 97 | new GridRenderer{_scene, &_debugDrawables}; 98 | 99 | _camera->draw(_debugDrawables); 100 | ``` 101 | 102 | ![GridRenderer](https://raw.githubusercontent.com/alexesDev/magnum-tips/master/GridRenderer.png) 103 | 104 | ### MathUtils 105 | 106 | getCameraToViewportRay: 107 | 108 | ```cpp 109 | Vector2 screenPoint = Vector2{_mousePosition} / Vector2{windowSize()}; 110 | Ray cameraRay = getCameraToViewportRay(_cameraController->camera(), screenPoint); 111 | 112 | Vector4 ground = Math::planeEquation(Vector3{0, 1, 0}, Vector3(0)); 113 | Float t = Math::Intersection::planeLine(ground, cameraRay.origin, cameraRay.direction); 114 | 115 | if (!Magnum::Math::isInf(t) && !Magnum::Math::isNan(t)) { 116 | Vector3 point = cameraRay.origin + cameraRay.direction * t; 117 | _line->setTo(point); 118 | } 119 | ``` 120 | -------------------------------------------------------------------------------- /ThirdPersonCameraController.cpp: -------------------------------------------------------------------------------- 1 | #include "ThirdPersonCameraController.h" 2 | 3 | using namespace Magnum; 4 | 5 | ThirdPersonCameraController::ThirdPersonCameraController(Object3D& object) : Object3D{&object} { 6 | _yawObject = new Object3D{this}; 7 | _pitchObject = new Object3D{_yawObject}; 8 | 9 | _cameraObject = new Object3D{_pitchObject}; 10 | _cameraObject->setTransformation(Matrix4::lookAt({ 7, 7, 0 }, Vector3{}, Vector3::yAxis(1))); 11 | 12 | _camera = new SceneGraph::Camera3D{*_cameraObject}; 13 | } 14 | 15 | ThirdPersonCameraController& ThirdPersonCameraController::move(const Magnum::Vector2i& shift) { 16 | Vector2 s = Vector2{shift} * _speed; 17 | 18 | _yawObject->rotate(Rad(s.x()), Vector3::yAxis(1)); 19 | _pitchObject->rotate(Rad(s.y()), Vector3::zAxis(1)); 20 | 21 | return *this; 22 | } 23 | -------------------------------------------------------------------------------- /ThirdPersonCameraController.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexesDev/magnum-tips/8a2e94809075d7d598110edf66b69f6f23335773/ThirdPersonCameraController.gif -------------------------------------------------------------------------------- /ThirdPersonCameraController.h: -------------------------------------------------------------------------------- 1 | #ifndef ThirdPersonCameraController_h 2 | #define ThirdPersonCameraController_h 3 | 4 | #include 5 | #include "Types.h" 6 | 7 | class ThirdPersonCameraController : public Object3D { 8 | public: 9 | explicit ThirdPersonCameraController(Object3D& object); 10 | 11 | Magnum::SceneGraph::Camera3D& camera() const { 12 | return *_camera; 13 | } 14 | 15 | Object3D& cameraObject() const { 16 | return *_cameraObject; 17 | } 18 | 19 | ThirdPersonCameraController& move(const Magnum::Vector2i& shift); 20 | 21 | ThirdPersonCameraController& setSpeed(const Magnum::Vector2 &speed) { 22 | _speed = speed; 23 | return *this; 24 | } 25 | 26 | private: 27 | Object3D* _yawObject; 28 | Object3D* _pitchObject; 29 | Object3D* _cameraObject; 30 | 31 | Magnum::SceneGraph::Camera3D* _camera; 32 | Magnum::Vector2 _speed{-0.05f, 0.05f}; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /TranslateController.cpp: -------------------------------------------------------------------------------- 1 | #include "TranslateController.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace Magnum; 16 | 17 | class ObjectRenderer : SceneGraph::Drawable3D { 18 | public: 19 | ObjectRenderer(Object3D &parent, SceneGraph::DrawableGroup3D *group, std::function drawCheck) : SceneGraph::Drawable3D{parent, group}, _drawCheck(drawCheck) { 20 | /* Shader */ 21 | _shader = DebugTools::ResourceManager::instance().get("TranslateController-shader"); 22 | if(!_shader) DebugTools::ResourceManager::instance().set(_shader.key(), new Shaders::VertexColor3D); 23 | 24 | /* Mesh and vertex buffer */ 25 | _mesh = DebugTools::ResourceManager::instance().get("TranslateController-mesh"); 26 | 27 | if(_mesh) return; 28 | 29 | /* Create the mesh */ 30 | GL::Buffer vertexBuffer{GL::Buffer::TargetHint::Array}; 31 | GL::Buffer indexBuffer{GL::Buffer::TargetHint::ElementArray}; 32 | GL::Mesh* mesh = new GL::Mesh; 33 | 34 | auto data = Primitives::axis3D(); 35 | 36 | vertexBuffer.setData(MeshTools::interleave(data.positions(0), data.colors(0)), GL::BufferUsage::StaticDraw); 37 | indexBuffer.setData(MeshTools::compressIndicesAs(data.indices()), GL::BufferUsage::StaticDraw); 38 | 39 | mesh->setPrimitive(GL::MeshPrimitive::Lines) 40 | .setCount(data.indices().size()) 41 | .addVertexBuffer(std::move(vertexBuffer), 0, Shaders::VertexColor3D::Position(), Shaders::VertexColor3D::Color4{}) 42 | .setIndexBuffer(std::move(indexBuffer), 0, GL::MeshIndexType::UnsignedByte, 0, data.positions(0).size()); 43 | 44 | DebugTools::ResourceManager::instance().set(_mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); 45 | } 46 | 47 | private: 48 | void draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) override { 49 | if (_drawCheck()) { 50 | _shader->setTransformationProjectionMatrix(camera.projectionMatrix() * transformationMatrix); 51 | _mesh->draw(*_shader); 52 | } 53 | } 54 | 55 | Resource _shader; 56 | Resource _mesh; 57 | std::function _drawCheck; 58 | }; 59 | 60 | TranslateController::TranslateController(Object3D *parent, SceneGraph::DrawableGroup3D *group) : Object3D(parent) { 61 | new ObjectRenderer{*this, group, [this](){ 62 | return children().first(); 63 | }}; 64 | } 65 | 66 | void TranslateController::move(const Ray &cameraRay) { 67 | if (_missed) { 68 | return; 69 | } 70 | 71 | Float t = Math::Intersection::planeLine(_plane, cameraRay.origin, cameraRay.direction); 72 | 73 | if (Magnum::Math::isInf(t) || Magnum::Math::isNan(t)) { 74 | return; 75 | } 76 | 77 | Vector3 currentPoint = cameraRay.origin + cameraRay.direction * t; 78 | 79 | Matrix4 tr = transformation(); 80 | tr.translation() = _startPosition + _dir * (currentPoint - _startPoint); 81 | setTransformation(tr); 82 | } 83 | 84 | void TranslateController::grab(const Ray &cameraRay) { 85 | if (!children().first()) { 86 | return; 87 | } 88 | 89 | _startPosition = transformation().translation(); 90 | _missed = true; 91 | 92 | // check x-z 93 | _plane = Math::planeEquation(Vector3::yAxis(1), _startPosition); 94 | Float t = Math::Intersection::planeLine(_plane, cameraRay.origin, cameraRay.direction); 95 | 96 | if (Magnum::Math::isInf(t) || Magnum::Math::isNan(t)) { 97 | return; 98 | } 99 | 100 | _startPoint = cameraRay.origin + cameraRay.direction * t; 101 | Vector3 p = _startPoint - _startPosition; 102 | 103 | if (Math::abs(p.z()) < _axisThreshold && p.x() > 0 && p.x() <= 1) { 104 | _dir = Vector3::xAxis(1); 105 | _missed = false; 106 | return; 107 | } 108 | 109 | if (Math::abs(p.x()) < _axisThreshold && p.z() > 0 && p.z() <= 1) { 110 | _dir = Vector3::zAxis(1); 111 | _missed = false; 112 | return; 113 | } 114 | 115 | // check y 116 | _plane = Math::planeEquation(Vector3::xAxis(1), _startPosition); 117 | t = Math::Intersection::planeLine(_plane, cameraRay.origin, cameraRay.direction); 118 | 119 | if (Magnum::Math::isInf(t) || Magnum::Math::isNan(t)) { 120 | return; 121 | } 122 | 123 | _startPoint = cameraRay.origin + cameraRay.direction * t; 124 | p = _startPoint - _startPosition; 125 | 126 | if (Math::abs(p.z()) < _axisThreshold && p.y() > 0 && p.y() <= 1) { 127 | _dir = Vector3::yAxis(1); 128 | _missed = false; 129 | return; 130 | } 131 | } 132 | 133 | void TranslateController::release() { 134 | _missed = true; 135 | } 136 | -------------------------------------------------------------------------------- /TranslateController.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexesDev/magnum-tips/8a2e94809075d7d598110edf66b69f6f23335773/TranslateController.gif -------------------------------------------------------------------------------- /TranslateController.h: -------------------------------------------------------------------------------- 1 | #ifndef TranslateController_h 2 | #define TranslateController_h 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | class TranslateController : public Object3D { 10 | public: 11 | explicit TranslateController(Object3D *parent = nullptr, Magnum::SceneGraph::DrawableGroup3D *group = nullptr); 12 | 13 | void grab(const Ray &cameraRay); 14 | void move(const Ray &cameraRay); 15 | void release(); 16 | 17 | private: 18 | Magnum::Vector3 _startPosition; 19 | Magnum::Vector3 _startPoint; 20 | Magnum::Vector3 _dir; 21 | Magnum::Vector4 _plane; 22 | Magnum::Float _axisThreshold = 0.3f; 23 | 24 | bool _missed = true; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Types.h: -------------------------------------------------------------------------------- 1 | #ifndef Types_h 2 | #define Types_h 3 | 4 | #include 5 | #include 6 | 7 | typedef Magnum::SceneGraph::Object Object3D; 8 | typedef Magnum::SceneGraph::Scene Scene3D; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | *.kdev4 3 | *~ 4 | -------------------------------------------------------------------------------- /demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(MyApplication) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/modules/") 5 | 6 | add_subdirectory(src) 7 | -------------------------------------------------------------------------------- /demo/README.md: -------------------------------------------------------------------------------- 1 | # Demo 2 | 3 | ``` 4 | mkdir build && cd build 5 | cmake .. 6 | cmake --build . 7 | ``` 8 | -------------------------------------------------------------------------------- /demo/modules/FindCorrade.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # Find Corrade 3 | # ------------ 4 | # 5 | # Finds the Corrade library. Basic usage:: 6 | # 7 | # find_package(Corrade REQUIRED) 8 | # 9 | # This module tries to find the base Corrade library and then defines the 10 | # following: 11 | # 12 | # Corrade_FOUND - Whether the base library was found 13 | # CORRADE_LIB_SUFFIX_MODULE - Path to CorradeLibSuffix.cmake module 14 | # 15 | # This command will try to find only the base library, not the optional 16 | # components, which are: 17 | # 18 | # Containers - Containers library 19 | # PluginManager - PluginManager library 20 | # TestSuite - TestSuite library 21 | # Utility - Utility library 22 | # rc - corrade-rc executable 23 | # 24 | # Example usage with specifying additional components is:: 25 | # 26 | # find_package(Corrade REQUIRED Utility TestSuite) 27 | # 28 | # For each component is then defined: 29 | # 30 | # Corrade_*_FOUND - Whether the component was found 31 | # Corrade::* - Component imported target 32 | # 33 | # The package is found if either debug or release version of each library is 34 | # found. If both debug and release libraries are found, proper version is 35 | # chosen based on actual build configuration of the project (i.e. Debug build 36 | # is linked to debug libraries, Release build to release libraries). 37 | # 38 | # Corrade conditionally defines ``CORRADE_IS_DEBUG_BUILD`` preprocessor 39 | # variable in case build configuration is ``Debug`` (not Corrade itself, but 40 | # build configuration of the project using it). Useful e.g. for selecting 41 | # proper plugin directory. 42 | # 43 | # Corrade defines the following custom target properties: 44 | # 45 | # CORRADE_CXX_STANDARD - C++ standard to require when compiling given 46 | # target. Does nothing if :variable:`CMAKE_CXX_FLAGS` already contains 47 | # particular standard setting flag or if given target contains 48 | # :prop_tgt:`CMAKE_CXX_STANDARD` property. Allowed value is 11, 14 or 17. 49 | # INTERFACE_CORRADE_CXX_STANDARD - C++ standard to require when using given 50 | # target. Does nothing if :variable:`CMAKE_CXX_FLAGS` already contains 51 | # particular standard setting flag or if given target contains 52 | # :prop_tgt:`CMAKE_CXX_STANDARD` property. Allowed value is 11, 14 or 17. 53 | # CORRADE_USE_PEDANTIC_FLAGS - Enable additional compiler/linker flags. 54 | # Boolean. 55 | # 56 | # These properties are inherited from directory properties, meaning that if you 57 | # set them on directories, they get implicitly set on all targets in given 58 | # directory (with a possibility to do target-specific overrides). All Corrade 59 | # libraries have the :prop_tgt:`INTERFACE_CORRADE_CXX_STANDARD` property set to 60 | # 11, meaning that you will always have at least C++11 enabled once you link to 61 | # any Corrade library. 62 | # 63 | # Features of found Corrade library are exposed in these variables: 64 | # 65 | # CORRADE_MSVC2017_COMPATIBILITY - Defined if compiled with compatibility 66 | # mode for MSVC 2017 67 | # CORRADE_MSVC2015_COMPATIBILITY - Defined if compiled with compatibility 68 | # mode for MSVC 2015 69 | # CORRADE_BUILD_DEPRECATED - Defined if compiled with deprecated APIs 70 | # included 71 | # CORRADE_BUILD_STATIC - Defined if compiled as static libraries. 72 | # Default are shared libraries. 73 | # CORRADE_TARGET_UNIX - Defined if compiled for some Unix flavor 74 | # (Linux, BSD, macOS) 75 | # CORRADE_TARGET_APPLE - Defined if compiled for Apple platforms 76 | # CORRADE_TARGET_IOS - Defined if compiled for iOS (device or 77 | # simulator) 78 | # CORRADE_TARGET_IOS_SIMULATOR - Defined if compiled for iOS Simulator 79 | # CORRADE_TARGET_WINDOWS - Defined if compiled for Windows 80 | # CORRADE_TARGET_WINDOWS_RT - Defined if compiled for Windows RT 81 | # CORRADE_TARGET_EMSCRIPTEN - Defined if compiled for Emscripten 82 | # CORRADE_TARGET_ANDROID - Defined if compiled for Android 83 | # CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT - Defined if PluginManager 84 | # doesn't support dynamic plugin loading due to platform limitations 85 | # CORRADE_TESTSUITE_TARGET_XCTEST - Defined if TestSuite is targetting Xcode 86 | # XCTest 87 | # CORRADE_UTILITY_USE_ANSI_COLORS - Defined if ANSI escape sequences are used 88 | # for colored output with Utility::Debug on Windows 89 | # 90 | # Additionally these variables are defined for internal usage: 91 | # 92 | # CORRADE_INCLUDE_DIR - Root include dir 93 | # CORRADE_*_LIBRARY_DEBUG - Debug version of given library, if found 94 | # CORRADE_*_LIBRARY_RELEASE - Release version of given library, if found 95 | # CORRADE_*_EXECUTABLE - Location of given executable, if found 96 | # CORRADE_USE_MODULE - Path to UseCorrade.cmake module (included 97 | # automatically) 98 | # CORRADE_TESTSUITE_XCTEST_RUNNER - Path to XCTestRunner.mm.in file 99 | # CORRADE_TESTSUITE_ADB_RUNNER - Path to AdbRunner.sh file 100 | # CORRADE_PEDANTIC_COMPILER_OPTIONS - List of pedantic compiler options used 101 | # for targets with :prop_tgt:`CORRADE_USE_PEDANTIC_FLAGS` enabled 102 | # CORRADE_PEDANTIC_COMPILER_DEFINITIONS - List of pedantic compiler 103 | # definitions used for targets with :prop_tgt:`CORRADE_USE_PEDANTIC_FLAGS` 104 | # enabled 105 | # 106 | # Workflows without :prop_tgt:`IMPORTED` targets are deprecated and the 107 | # following variables are included just for backwards compatibility and only if 108 | # :variable:`CORRADE_BUILD_DEPRECATED` is enabled: 109 | # 110 | # CORRADE_CXX_FLAGS - Pedantic compile flags. Use 111 | # :prop_tgt:`CORRADE_USE_PEDANTIC_FLAGS` property or 112 | # :variable:`CORRADE_PEDANTIC_COMPILER_DEFINITIONS` / 113 | # :variable:`CORRADE_PEDANTIC_COMPILER_OPTIONS` list variables instead. 114 | # 115 | # Corrade provides these macros and functions: 116 | # 117 | # .. command:: corrade_add_test 118 | # 119 | # Add unit test using Corrade's TestSuite:: 120 | # 121 | # corrade_add_test( 122 | # ... 123 | # [LIBRARIES ...] 124 | # [FILES ...] 125 | # [ARGUMENTS ...]) 126 | # 127 | # Test name is also executable name. You can use ``LIBRARIES`` to specify 128 | # libraries to link with instead of using :command:`target_link_libraries()`. 129 | # The ``Corrade::TestSuite`` target is linked automatically to each test. Note 130 | # that the :command:`enable_testing()` function must be called explicitly. 131 | # Arguments passed after ``ARGUMENTS`` will be appended to the test 132 | # command line. ``ARGUMENTS`` are supported everywhere except when 133 | # ``CORRADE_TESTSUITE_TARGET_XCTEST`` is enabled. 134 | # 135 | # You can list files needed by the test in the ``FILES`` section. If given 136 | # filename is relative, it is treated relatively to `CMAKE_CURRENT_SOURCE_DIR`. 137 | # The files are added to the :prop_test:`REQUIRED_FILES` target property. On 138 | # Emscripten they are bundled to the executable and available in the virtual 139 | # filesystem root. On Android they are copied along the executable to the 140 | # target. In case of Emscripten and Android, if the file is absolute or 141 | # contains ``..``, only the leaf name is used. Alternatively you can have a 142 | # filename formatted as ``@``, in which case the ```` is 143 | # treated as local filesystem location and ```` as remote/virtual 144 | # filesystem location. The remote location can't be absolute or contain ``..`` 145 | # / ``@`` characters. 146 | # 147 | # Unless :variable:`CORRADE_TESTSUITE_TARGET_XCTEST` is set, test cases on iOS 148 | # targets are created as bundles with bundle identifier set to CMake project 149 | # name by default. Use the cache variable :variable:`CORRADE_TESTSUITE_BUNDLE_IDENTIFIER_PREFIX` 150 | # to change it to something else. 151 | # 152 | # .. command:: corrade_add_resource 153 | # 154 | # Compile data resources into application binary:: 155 | # 156 | # corrade_add_resource( ) 157 | # 158 | # Depends on ``Corrade::rc``, which is part of Corrade utilities. This command 159 | # generates resource data using given configuration file in current build 160 | # directory. Argument name is name under which the resources can be explicitly 161 | # loaded. Variable ```` contains compiled resource filename, which is 162 | # then used for compiling library / executable. On CMake >= 3.1 the 163 | # `resources.conf` file can contain UTF-8-encoded filenames. Example usage:: 164 | # 165 | # corrade_add_resource(app_resources resources.conf) 166 | # add_executable(app source1 source2 ... ${app_resources}) 167 | # 168 | # .. command:: corrade_add_plugin 169 | # 170 | # Add dynamic plugin:: 171 | # 172 | # corrade_add_plugin( 173 | # ";" 174 | # ";" 175 | # 176 | # ...) 177 | # 178 | # The macro adds preprocessor directive ``CORRADE_DYNAMIC_PLUGIN``. Additional 179 | # libraries can be linked in via :command:`target_link_libraries(plugin_name ...) `. 180 | # On DLL platforms, the plugin DLLs and metadata files are put into 181 | # ````/```` and the 182 | # ``*.lib`` files into ````/````. 183 | # On non-DLL platforms everything is put into ````/ 184 | # ````. 185 | # 186 | # corrade_add_plugin( 187 | # 188 | # 189 | # 190 | # ...) 191 | # 192 | # Unline the above version this puts everything into ```` on 193 | # both DLL and non-DLL platforms. If ```` is set to 194 | # :variable:`CMAKE_CURRENT_BINARY_DIR` (e.g. for testing purposes), the files 195 | # are copied directly, without the need to perform install step. Note that the 196 | # files are actually put into configuration-based subdirectory, i.e. 197 | # ``${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}``. See documentation of 198 | # :variable:`CMAKE_CFG_INTDIR` variable for more information. 199 | # 200 | # .. command:: corrade_add_static_plugin 201 | # 202 | # Add static plugin:: 203 | # 204 | # corrade_add_static_plugin( 205 | # ";" 206 | # 207 | # ...) 208 | # 209 | # The macro adds preprocessor directive ``CORRADE_STATIC_PLUGIN``. Additional 210 | # libraries can be linked in via :command:`target_link_libraries(plugin_name ...) `. 211 | # The ```` is ignored and included just for compatibility 212 | # with the :command:`corrade_add_plugin` command, everything is installed into 213 | # ````. Note that plugins built in debug configuration 214 | # (e.g. with :variable:`CMAKE_BUILD_TYPE` set to ``Debug``) have ``"-d"`` 215 | # suffix to make it possible to have both debug and release plugins installed 216 | # alongside each other. 217 | # 218 | # corrade_add_static_plugin( 219 | # 220 | # 221 | # ...) 222 | # 223 | # Equivalent to the above with ```` set to ````. 224 | # If ```` is set to :variable:`CMAKE_CURRENT_BINARY_DIR` (e.g. for 225 | # testing purposes), no installation rules are added. 226 | # 227 | # .. command:: corrade_find_dlls_for_libs 228 | # 229 | # Find corresponding DLLs for library files:: 230 | # 231 | # corrade_find_dlls_for_libs( ...) 232 | # 233 | # Available only on Windows, for all ``*.lib`` files tries to find 234 | # corresponding DLL file. Useful for bundling dependencies for e.g. WinRT 235 | # packages. 236 | # 237 | 238 | # 239 | # This file is part of Corrade. 240 | # 241 | # Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 242 | # 2017, 2018, 2019 Vladimír Vondruš 243 | # 244 | # Permission is hereby granted, free of charge, to any person obtaining a 245 | # copy of this software and associated documentation files (the "Software"), 246 | # to deal in the Software without restriction, including without limitation 247 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 248 | # and/or sell copies of the Software, and to permit persons to whom the 249 | # Software is furnished to do so, subject to the following conditions: 250 | # 251 | # The above copyright notice and this permission notice shall be included 252 | # in all copies or substantial portions of the Software. 253 | # 254 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 255 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 256 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 257 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 258 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 259 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 260 | # DEALINGS IN THE SOFTWARE. 261 | # 262 | 263 | # Root include dir 264 | find_path(CORRADE_INCLUDE_DIR 265 | NAMES Corrade/Corrade.h) 266 | mark_as_advanced(CORRADE_INCLUDE_DIR) 267 | 268 | # Configuration file 269 | find_file(_CORRADE_CONFIGURE_FILE configure.h 270 | HINTS ${CORRADE_INCLUDE_DIR}/Corrade/) 271 | mark_as_advanced(_CORRADE_CONFIGURE_FILE) 272 | 273 | # We need to open configure.h file from CORRADE_INCLUDE_DIR before we check for 274 | # the components. Bail out with proper error message if it wasn't found. The 275 | # complete check with all components is further below. 276 | if(NOT CORRADE_INCLUDE_DIR) 277 | include(FindPackageHandleStandardArgs) 278 | find_package_handle_standard_args(Corrade 279 | REQUIRED_VARS CORRADE_INCLUDE_DIR _CORRADE_CONFIGURE_FILE) 280 | endif() 281 | 282 | # Read flags from configuration 283 | file(READ ${_CORRADE_CONFIGURE_FILE} _corradeConfigure) 284 | set(_corradeFlags 285 | MSVC2015_COMPATIBILITY 286 | MSVC2017_COMPATIBILITY 287 | BUILD_DEPRECATED 288 | BUILD_STATIC 289 | TARGET_UNIX 290 | TARGET_APPLE 291 | TARGET_IOS 292 | TARGET_IOS_SIMULATOR 293 | TARGET_WINDOWS 294 | TARGET_WINDOWS_RT 295 | TARGET_EMSCRIPTEN 296 | TARGET_ANDROID 297 | PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT 298 | TESTSUITE_TARGET_XCTEST 299 | UTILITY_USE_ANSI_COLORS) 300 | foreach(_corradeFlag ${_corradeFlags}) 301 | string(FIND "${_corradeConfigure}" "#define CORRADE_${_corradeFlag}" _corrade_${_corradeFlag}) 302 | if(NOT _corrade_${_corradeFlag} EQUAL -1) 303 | set(CORRADE_${_corradeFlag} 1) 304 | endif() 305 | endforeach() 306 | 307 | # CMake module dir 308 | find_path(_CORRADE_MODULE_DIR 309 | NAMES UseCorrade.cmake CorradeLibSuffix.cmake 310 | PATH_SUFFIXES share/cmake/Corrade) 311 | mark_as_advanced(_CORRADE_MODULE_DIR) 312 | 313 | set(CORRADE_USE_MODULE ${_CORRADE_MODULE_DIR}/UseCorrade.cmake) 314 | set(CORRADE_LIB_SUFFIX_MODULE ${_CORRADE_MODULE_DIR}/CorradeLibSuffix.cmake) 315 | 316 | # Ensure that all inter-component dependencies are specified as well 317 | foreach(_component ${Corrade_FIND_COMPONENTS}) 318 | string(TOUPPER ${_component} _COMPONENT) 319 | 320 | if(_component STREQUAL Containers) 321 | set(_CORRADE_${_COMPONENT}_DEPENDENCIES Utility) 322 | elseif(_component STREQUAL Interconnect) 323 | set(_CORRADE_${_COMPONENT}_DEPENDENCIES Utility) 324 | elseif(_component STREQUAL PluginManager) 325 | set(_CORRADE_${_COMPONENT}_DEPENDENCIES Containers Utility rc) 326 | elseif(_component STREQUAL TestSuite) 327 | set(_CORRADE_${_COMPONENT}_DEPENDENCIES Utility) 328 | elseif(_component STREQUAL Utility) 329 | set(_CORRADE_${_COMPONENT}_DEPENDENCIES Containers rc) 330 | endif() 331 | 332 | # Mark the dependencies as required if the component is also required 333 | if(Corrade_FIND_REQUIRED_${_component}) 334 | foreach(_dependency ${_CORRADE_${_COMPONENT}_DEPENDENCIES}) 335 | set(Corrade_FIND_REQUIRED_${_dependency} TRUE) 336 | endforeach() 337 | endif() 338 | 339 | list(APPEND _CORRADE_ADDITIONAL_COMPONENTS ${_CORRADE_${_COMPONENT}_DEPENDENCIES}) 340 | endforeach() 341 | 342 | # Join the lists, remove duplicate components 343 | if(_CORRADE_ADDITIONAL_COMPONENTS) 344 | list(INSERT Corrade_FIND_COMPONENTS 0 ${_CORRADE_ADDITIONAL_COMPONENTS}) 345 | endif() 346 | if(Corrade_FIND_COMPONENTS) 347 | list(REMOVE_DUPLICATES Corrade_FIND_COMPONENTS) 348 | endif() 349 | 350 | # Component distinction 351 | set(_CORRADE_LIBRARY_COMPONENTS "^(Containers|Interconnect|PluginManager|TestSuite|Utility)$") 352 | set(_CORRADE_HEADER_ONLY_COMPONENTS "^(Containers)$") 353 | set(_CORRADE_EXECUTABLE_COMPONENTS "^(rc)$") 354 | 355 | # Find all components 356 | foreach(_component ${Corrade_FIND_COMPONENTS}) 357 | string(TOUPPER ${_component} _COMPONENT) 358 | 359 | # Create imported target in case the library is found. If the project is 360 | # added as subproject to CMake, the target already exists and all the 361 | # required setup is already done from the build tree. 362 | if(TARGET Corrade::${_component}) 363 | set(Corrade_${_component}_FOUND TRUE) 364 | else() 365 | # Library components 366 | if(_component MATCHES ${_CORRADE_LIBRARY_COMPONENTS} AND NOT _component MATCHES ${_CORRADE_HEADER_ONLY_COMPONENTS}) 367 | add_library(Corrade::${_component} UNKNOWN IMPORTED) 368 | 369 | # Try to find both debug and release version 370 | find_library(CORRADE_${_COMPONENT}_LIBRARY_DEBUG Corrade${_component}-d) 371 | find_library(CORRADE_${_COMPONENT}_LIBRARY_RELEASE Corrade${_component}) 372 | mark_as_advanced(CORRADE_${_COMPONENT}_LIBRARY_DEBUG 373 | CORRADE_${_COMPONENT}_LIBRARY_RELEASE) 374 | 375 | if(CORRADE_${_COMPONENT}_LIBRARY_RELEASE) 376 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 377 | IMPORTED_CONFIGURATIONS RELEASE) 378 | set_property(TARGET Corrade::${_component} PROPERTY 379 | IMPORTED_LOCATION_RELEASE ${CORRADE_${_COMPONENT}_LIBRARY_RELEASE}) 380 | endif() 381 | 382 | if(CORRADE_${_COMPONENT}_LIBRARY_DEBUG) 383 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 384 | IMPORTED_CONFIGURATIONS DEBUG) 385 | set_property(TARGET Corrade::${_component} PROPERTY 386 | IMPORTED_LOCATION_DEBUG ${CORRADE_${_COMPONENT}_LIBRARY_DEBUG}) 387 | endif() 388 | endif() 389 | 390 | # Header-only library components 391 | if(_component MATCHES ${_CORRADE_HEADER_ONLY_COMPONENTS}) 392 | add_library(Corrade::${_component} INTERFACE IMPORTED) 393 | endif() 394 | 395 | # Executable components 396 | if(_component MATCHES ${_CORRADE_EXECUTABLE_COMPONENTS}) 397 | add_executable(Corrade::${_component} IMPORTED) 398 | 399 | find_program(CORRADE_${_COMPONENT}_EXECUTABLE corrade-${_component}) 400 | mark_as_advanced(CORRADE_${_COMPONENT}_EXECUTABLE) 401 | 402 | if(CORRADE_${_COMPONENT}_EXECUTABLE) 403 | set_property(TARGET Corrade::${_component} PROPERTY 404 | IMPORTED_LOCATION ${CORRADE_${_COMPONENT}_EXECUTABLE}) 405 | endif() 406 | endif() 407 | 408 | # No special setup for Containers library 409 | # No special setup for Interconnect library 410 | 411 | # PluginManager library 412 | if(_component STREQUAL PluginManager) 413 | # At least static build needs this 414 | if(CORRADE_TARGET_UNIX) 415 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 416 | INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) 417 | endif() 418 | 419 | # TestSuite library has some additional files 420 | elseif(_component STREQUAL TestSuite) 421 | # XCTest runner file 422 | if(CORRADE_TESTSUITE_TARGET_XCTEST) 423 | find_file(CORRADE_TESTSUITE_XCTEST_RUNNER XCTestRunner.mm.in 424 | PATH_SUFFIXES share/corrade/TestSuite) 425 | set(CORRADE_TESTSUITE_XCTEST_RUNNER_NEEDED CORRADE_TESTSUITE_XCTEST_RUNNER) 426 | 427 | # ADB runner file 428 | elseif(CORRADE_TARGET_ANDROID) 429 | find_file(CORRADE_TESTSUITE_ADB_RUNNER AdbRunner.sh 430 | PATH_SUFFIXES share/corrade/TestSuite) 431 | set(CORRADE_TESTSUITE_ADB_RUNNER_NEEDED CORRADE_TESTSUITE_ADB_RUNNER) 432 | 433 | # Emscripten runner file 434 | elseif(CORRADE_TARGET_EMSCRIPTEN) 435 | find_file(CORRADE_TESTSUITE_EMSCRIPTEN_RUNNER EmscriptenRunner.html.in 436 | PATH_SUFFIXES share/corrade/TestSuite) 437 | set(CORRADE_TESTSUITE_EMSCRIPTEN_RUNNER_NEEDED CORRADE_TESTSUITE_EMSCRIPTEN_RUNNER) 438 | endif() 439 | 440 | # Utility library (contains all setup that is used by others) 441 | elseif(_component STREQUAL Utility) 442 | # Top-level include directory 443 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 444 | INTERFACE_INCLUDE_DIRECTORIES ${CORRADE_INCLUDE_DIR}) 445 | 446 | # Require (at least) C++11 for users 447 | set_property(TARGET Corrade::${_component} PROPERTY 448 | INTERFACE_CORRADE_CXX_STANDARD 11) 449 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 450 | COMPATIBLE_INTERFACE_NUMBER_MAX CORRADE_CXX_STANDARD) 451 | 452 | # AndroidLogStreamBuffer class needs to be linked to log library 453 | if(CORRADE_TARGET_ANDROID) 454 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 455 | INTERFACE_LINK_LIBRARIES "log") 456 | endif() 457 | endif() 458 | 459 | # Find library includes 460 | if(_component MATCHES ${_CORRADE_LIBRARY_COMPONENTS}) 461 | find_path(_CORRADE_${_COMPONENT}_INCLUDE_DIR 462 | NAMES ${_component}.h 463 | HINTS ${CORRADE_INCLUDE_DIR}/Corrade/${_component}) 464 | mark_as_advanced(_CORRADE_${_COMPONENT}_INCLUDE_DIR) 465 | endif() 466 | 467 | # Add inter-library dependencies 468 | if(_component MATCHES ${_CORRADE_LIBRARY_COMPONENTS} OR _component MATCHES ${_CORRADE_HEADER_ONLY_COMPONENTS}) 469 | foreach(_dependency ${_CORRADE_${_COMPONENT}_DEPENDENCIES}) 470 | if(_dependency MATCHES ${_CORRADE_LIBRARY_COMPONENTS} OR _dependency MATCHES ${_CORRADE_HEADER_ONLY_COMPONENTS}) 471 | set_property(TARGET Corrade::${_component} APPEND PROPERTY 472 | INTERFACE_LINK_LIBRARIES Corrade::${_dependency}) 473 | endif() 474 | endforeach() 475 | endif() 476 | 477 | # Decide if the component was found 478 | if((_component MATCHES ${_CORRADE_LIBRARY_COMPONENTS} AND _CORRADE_${_COMPONENT}_INCLUDE_DIR AND (_component MATCHES ${_CORRADE_HEADER_ONLY_COMPONENTS} OR CORRADE_${_COMPONENT}_LIBRARY_RELEASE OR CORRADE_${_COMPONENT}_LIBRARY_DEBUG)) OR (_component MATCHES ${_CORRADE_EXECUTABLE_COMPONENTS} AND CORRADE_${_COMPONENT}_EXECUTABLE)) 479 | set(Corrade_${_component}_FOUND TRUE) 480 | else() 481 | set(Corrade_${_component}_FOUND FALSE) 482 | endif() 483 | endif() 484 | endforeach() 485 | 486 | include(FindPackageHandleStandardArgs) 487 | find_package_handle_standard_args(Corrade REQUIRED_VARS 488 | CORRADE_INCLUDE_DIR 489 | _CORRADE_MODULE_DIR 490 | _CORRADE_CONFIGURE_FILE 491 | ${CORRADE_TESTSUITE_XCTEST_RUNNER_NEEDED} 492 | ${CORRADE_TESTSUITE_ADB_RUNNER_NEEDED} 493 | ${CORRADE_TESTSUITE_EMSCRIPTEN_RUNNER_NEEDED} 494 | HANDLE_COMPONENTS) 495 | 496 | # Finalize the finding process 497 | include(${CORRADE_USE_MODULE}) 498 | -------------------------------------------------------------------------------- /demo/modules/FindMagnum.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # Find Magnum 3 | # ----------- 4 | # 5 | # Finds the Magnum library. Basic usage:: 6 | # 7 | # find_package(Magnum REQUIRED) 8 | # 9 | # This module tries to find the base Magnum library and then defines the 10 | # following: 11 | # 12 | # Magnum_FOUND - Whether the base library was found 13 | # MAGNUM_DEPLOY_PREFIX - Prefix where to put final application 14 | # executables, defaults to ``.``. If a relative path is used, it's relative 15 | # to :variable:`CMAKE_INSTALL_PREFIX`. 16 | # MAGNUM_INCLUDE_INSTALL_PREFIX - Prefix where to put platform-independent 17 | # include and other files, defaults to ``.``. If a relative path is used, 18 | # it's relative to :variable:`CMAKE_INSTALL_PREFIX`. 19 | # MAGNUM_PLUGINS_DEBUG_DIR - Base directory with dynamic plugins for 20 | # debug builds, defaults to magnum-d/ subdirectory of dir where Magnum 21 | # library was found 22 | # MAGNUM_PLUGINS_RELEASE_DIR - Base directory with dynamic plugins for 23 | # release builds, defaults to magnum/ subdirectory of dir where Magnum 24 | # library was found 25 | # MAGNUM_PLUGINS_DIR - Base directory with dynamic plugins, defaults 26 | # to :variable:`MAGNUM_PLUGINS_RELEASE_DIR` in release builds and 27 | # multi-configuration builds or to :variable:`MAGNUM_PLUGINS_DEBUG_DIR` in 28 | # debug builds. You can modify all three variables (e.g. set them to ``.`` 29 | # when deploying on Windows with plugins stored relatively to the 30 | # executable), the following ``MAGNUM_PLUGINS_*_DIR`` variables depend on it. 31 | # MAGNUM_PLUGINS_FONT[|_DEBUG|_RELEASE]_DIR - Directory with dynamic font 32 | # plugins 33 | # MAGNUM_PLUGINS_FONTCONVERTER[|_DEBUG|_RELEASE]_DIR - Directory with dynamic 34 | # font converter plugins 35 | # MAGNUM_PLUGINS_IMAGECONVERTER[|_DEBUG|_RELEASE]_DIR - Directory with dynamic 36 | # image converter plugins 37 | # MAGNUM_PLUGINS_IMPORTER[|_DEBUG|_RELEASE]_DIR - Directory with dynamic 38 | # importer plugins 39 | # MAGNUM_PLUGINS_AUDIOIMPORTER[|_DEBUG|_RELEASE]_DIR - Directory with dynamic 40 | # audio importer plugins 41 | # 42 | # If Magnum is built for Emscripten, the following variables contain paths to 43 | # various support files: 44 | # 45 | # MAGNUM_EMSCRIPTENAPPLICATION_JS - Path to the EmscriptenApplication.js file 46 | # MAGNUM_WINDOWLESSEMSCRIPTENAPPLICATION_JS - Path to the 47 | # WindowlessEmscriptenApplication.js file 48 | # MAGNUM_WEBAPPLICATION_CSS - Path to the WebApplication.css file 49 | # 50 | # This command will try to find only the base library, not the optional 51 | # components. The base library depends on Corrade and OpenGL libraries (or 52 | # OpenGL ES libraries). Additional dependencies are specified by the 53 | # components. The optional components are: 54 | # 55 | # AnyAudioImporter - Any audio importer 56 | # AnyImageConverter - Any image converter 57 | # AnyImageImporter - Any image importer 58 | # AnySceneImporter - Any scene importer 59 | # Audio - Audio library 60 | # DebugTools - DebugTools library 61 | # GL - GL library 62 | # MeshTools - MeshTools library 63 | # Primitives - Primitives library 64 | # SceneGraph - SceneGraph library 65 | # Shaders - Shaders library 66 | # Shapes - Shapes library 67 | # Text - Text library 68 | # TextureTools - TextureTools library 69 | # Trade - Trade library 70 | # Vk - Vk library 71 | # GlfwApplication - GLFW application 72 | # GlutApplication - GLUT application 73 | # GlxApplication - GLX application 74 | # Sdl2Application - SDL2 application 75 | # XEglApplication - X/EGL application 76 | # WindowlessCglApplication - Windowless CGL application 77 | # WindowlessEglApplication - Windowless EGL application 78 | # WindowlessGlxApplication - Windowless GLX application 79 | # WindowlessIosApplication - Windowless iOS application 80 | # WindowlessWglApplication - Windowless WGL application 81 | # WindowlessWindowsEglApplication - Windowless Windows/EGL application 82 | # CglContext - CGL context 83 | # EglContext - EGL context 84 | # GlxContext - GLX context 85 | # WglContext - WGL context 86 | # OpenGLTester - OpenGLTester class 87 | # MagnumFont - Magnum bitmap font plugin 88 | # MagnumFontConverter - Magnum bitmap font converter plugin 89 | # ObjImporter - OBJ importer plugin 90 | # TgaImageConverter - TGA image converter plugin 91 | # TgaImporter - TGA importer plugin 92 | # WavAudioImporter - WAV audio importer plugin 93 | # distancefieldconverter - magnum-distancefieldconverter executable 94 | # fontconverter - magnum-fontconverter executable 95 | # imageconverter - magnum-imageconverter executable 96 | # gl-info - magnum-gl-info executable 97 | # al-info - magnum-al-info executable 98 | # 99 | # Example usage with specifying additional components is:: 100 | # 101 | # find_package(Magnum REQUIRED Trade MeshTools Primitives GlutApplication) 102 | # 103 | # For each component is then defined: 104 | # 105 | # Magnum_*_FOUND - Whether the component was found 106 | # Magnum::* - Component imported target 107 | # 108 | # If exactly one ``*Application`` or exactly one ``Windowless*Application`` 109 | # component is requested and found, its target is available in convenience 110 | # alias ``Magnum::Application`` / ``Magnum::WindowlessApplication`` to simplify 111 | # porting. Similarly, if exactly one ``*Context`` component is requested and 112 | # found, its target is available in convenience alias ``Magnum::GLContext``. 113 | # 114 | # The package is found if either debug or release version of each requested 115 | # library (or plugin) is found. If both debug and release libraries (or 116 | # plugins) are found, proper version is chosen based on actual build 117 | # configuration of the project (i.e. Debug build is linked to debug libraries, 118 | # Release build to release libraries). Note that this autodetection might fail 119 | # for the :variable:`MAGNUM_PLUGINS_DIR` variable, especially on 120 | # multi-configuration build systems. You can make use of 121 | # ``CORRADE_IS_DEBUG_BUILD`` preprocessor variable along with 122 | # ``MAGNUM_PLUGINS_*_DEBUG_DIR`` / ``MAGNUM_PLUGINS_*_RELEASE_DIR`` variables 123 | # to decide in preprocessing step. 124 | # 125 | # Features of found Magnum library are exposed in these variables: 126 | # 127 | # MAGNUM_BUILD_DEPRECATED - Defined if compiled with deprecated APIs 128 | # included 129 | # MAGNUM_BUILD_STATIC - Defined if compiled as static libraries 130 | # MAGNUM_BUILD_MULTITHREADED - Defined if compiled in a way that allows 131 | # having multiple thread-local Magnum contexts 132 | # MAGNUM_TARGET_GL - Defined if compiled with OpenGL interop 133 | # MAGNUM_TARGET_GLES - Defined if compiled for OpenGL ES 134 | # MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0 135 | # MAGNUM_TARGET_GLES3 - Defined if compiled for OpenGL ES 3.0 136 | # MAGNUM_TARGET_DESKTOP_GLES - Defined if compiled with OpenGL ES 137 | # emulation on desktop OpenGL 138 | # MAGNUM_TARGET_WEBGL - Defined if compiled for WebGL 139 | # MAGNUM_TARGET_HEADLESS - Defined if compiled for headless machines 140 | # MAGNUM_TARGET_VK - Defined if compiled with Vulkan interop 141 | # 142 | # Additionally these variables are defined for internal usage: 143 | # 144 | # MAGNUM_INCLUDE_DIR - Root include dir (w/o dependencies) 145 | # MAGNUM_LIBRARY - Magnum library (w/o dependencies) 146 | # MAGNUM_LIBRARY_DEBUG - Debug version of Magnum library, if found 147 | # MAGNUM_LIBRARY_RELEASE - Release version of Magnum library, if found 148 | # MAGNUM_*_LIBRARY - Component libraries (w/o dependencies) 149 | # MAGNUM_*_LIBRARY_DEBUG - Debug version of given library, if found 150 | # MAGNUM_*_LIBRARY_RELEASE - Release version of given library, if found 151 | # MAGNUM_BINARY_INSTALL_DIR - Binary installation directory 152 | # MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory 153 | # MAGNUM_DATA_INSTALL_DIR - Data installation directory 154 | # MAGNUM_PLUGINS_[DEBUG|RELEASE]_BINARY_INSTALL_DIR - Plugin binary 155 | # installation directory 156 | # MAGNUM_PLUGINS_[DEBUG|RELEASE]_LIBRARY_INSTALL_DIR - Plugin library 157 | # installation directory 158 | # MAGNUM_PLUGINS_FONT_[DEBUG|RELEASE]_BINARY_INSTALL_DIR - Font plugin binary 159 | # installation directory 160 | # MAGNUM_PLUGINS_FONT_[DEBUG|RELEASE]_LIBRARY_INSTALL_DIR - Font plugin 161 | # library installation directory 162 | # MAGNUM_PLUGINS_FONTCONVERTER_[DEBUG|RELEASE]_BINARY_INSTALL_DIR - Font 163 | # converter plugin binary installation directory 164 | # MAGNUM_PLUGINS_FONTCONVERTER_[DEBUG|RELEASE]_LIBRARY_INSTALL_DIR - Font 165 | # converter plugin library installation directory 166 | # MAGNUM_PLUGINS_IMAGECONVERTER_[DEBUG|RELEASE]_BINARY_INSTALL_DIR - Image 167 | # converter plugin binary installation directory 168 | # MAGNUM_PLUGINS_IMAGECONVERTER_[DEBUG|RELEASE]_LIBRARY_INSTALL_DIR - Image 169 | # converter plugin library installation directory 170 | # MAGNUM_PLUGINS_IMPORTER_[DEBUG|RELEASE]_BINARY_INSTALL_DIR - Importer 171 | # plugin binary installation directory 172 | # MAGNUM_PLUGINS_IMPORTER_[DEBUG|RELEASE]_LIBRARY_INSTALL_DIR - Importer 173 | # plugin library installation directory 174 | # MAGNUM_PLUGINS_AUDIOIMPORTER_[DEBUG|RELEASE]_BINARY_INSTALL_DIR - Audio 175 | # importer plugin binary installation directory 176 | # MAGNUM_PLUGINS_AUDIOIMPORTER_[DEBUG|RELEASE]_LIBRARY_INSTALL_DIR - Audio 177 | # importer plugin library installation directory 178 | # MAGNUM_INCLUDE_INSTALL_DIR - Header installation directory 179 | # MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR - Plugin header installation directory 180 | # 181 | 182 | # 183 | # This file is part of Magnum. 184 | # 185 | # Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 186 | # Vladimír Vondruš 187 | # 188 | # Permission is hereby granted, free of charge, to any person obtaining a 189 | # copy of this software and associated documentation files (the "Software"), 190 | # to deal in the Software without restriction, including without limitation 191 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 192 | # and/or sell copies of the Software, and to permit persons to whom the 193 | # Software is furnished to do so, subject to the following conditions: 194 | # 195 | # The above copyright notice and this permission notice shall be included 196 | # in all copies or substantial portions of the Software. 197 | # 198 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 199 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 200 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 201 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 202 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 203 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 204 | # DEALINGS IN THE SOFTWARE. 205 | # 206 | 207 | # Corrade library dependencies 208 | set(_MAGNUM_CORRADE_DEPENDENCIES ) 209 | foreach(_component ${Magnum_FIND_COMPONENTS}) 210 | string(TOUPPER ${_component} _COMPONENT) 211 | 212 | # Unrolling the transitive dependencies here so this doesn't need to be 213 | # after resolving inter-component dependencies. Listing also all plugins. 214 | if(_component MATCHES "^(Audio|DebugTools|MeshTools|Primitives|Text|TextureTools|Trade|.+Importer|.+ImageConverter|.+Font)$") 215 | set(_MAGNUM_${_COMPONENT}_CORRADE_DEPENDENCIES PluginManager) 216 | endif() 217 | 218 | list(APPEND _MAGNUM_CORRADE_DEPENDENCIES ${_MAGNUM_${_COMPONENT}_CORRADE_DEPENDENCIES}) 219 | endforeach() 220 | find_package(Corrade REQUIRED Utility ${_MAGNUM_CORRADE_DEPENDENCIES}) 221 | 222 | # Root include dir 223 | find_path(MAGNUM_INCLUDE_DIR 224 | NAMES Magnum/Magnum.h) 225 | mark_as_advanced(MAGNUM_INCLUDE_DIR) 226 | 227 | # Configuration file 228 | find_file(_MAGNUM_CONFIGURE_FILE configure.h 229 | HINTS ${MAGNUM_INCLUDE_DIR}/Magnum/) 230 | mark_as_advanced(_MAGNUM_CONFIGURE_FILE) 231 | 232 | # We need to open configure.h file from MAGNUM_INCLUDE_DIR before we check for 233 | # the components. Bail out with proper error message if it wasn't found. The 234 | # complete check with all components is further below. 235 | if(NOT MAGNUM_INCLUDE_DIR) 236 | include(FindPackageHandleStandardArgs) 237 | find_package_handle_standard_args(Magnum 238 | REQUIRED_VARS MAGNUM_INCLUDE_DIR _MAGNUM_CONFIGURE_FILE) 239 | endif() 240 | 241 | # Read flags from configuration 242 | file(READ ${_MAGNUM_CONFIGURE_FILE} _magnumConfigure) 243 | set(_magnumFlags 244 | BUILD_DEPRECATED 245 | BUILD_STATIC 246 | BUILD_MULTITHREADED 247 | TARGET_GL 248 | TARGET_GLES 249 | TARGET_GLES2 250 | TARGET_GLES3 251 | TARGET_DESKTOP_GLES 252 | TARGET_WEBGL 253 | TARGET_HEADLESS 254 | TARGET_VK) 255 | foreach(_magnumFlag ${_magnumFlags}) 256 | string(FIND "${_magnumConfigure}" "#define MAGNUM_${_magnumFlag}" _magnum_${_magnumFlag}) 257 | if(NOT _magnum_${_magnumFlag} EQUAL -1) 258 | set(MAGNUM_${_magnumFlag} 1) 259 | endif() 260 | endforeach() 261 | 262 | # Base Magnum library 263 | if(NOT TARGET Magnum::Magnum) 264 | add_library(Magnum::Magnum UNKNOWN IMPORTED) 265 | 266 | # Try to find both debug and release version 267 | find_library(MAGNUM_LIBRARY_DEBUG Magnum-d) 268 | find_library(MAGNUM_LIBRARY_RELEASE Magnum) 269 | mark_as_advanced(MAGNUM_LIBRARY_DEBUG 270 | MAGNUM_LIBRARY_RELEASE) 271 | 272 | # Set the MAGNUM_LIBRARY variable based on what was found, use that 273 | # information to guess also build type of dynamic plugins 274 | if(MAGNUM_LIBRARY_DEBUG AND MAGNUM_LIBRARY_RELEASE) 275 | set(MAGNUM_LIBRARY ${MAGNUM_LIBRARY_RELEASE}) 276 | get_filename_component(_MAGNUM_PLUGINS_DIR_PREFIX ${MAGNUM_LIBRARY_DEBUG} PATH) 277 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 278 | set(_MAGNUM_PLUGINS_DIR_SUFFIX "-d") 279 | endif() 280 | elseif(MAGNUM_LIBRARY_DEBUG) 281 | set(MAGNUM_LIBRARY ${MAGNUM_LIBRARY_DEBUG}) 282 | get_filename_component(_MAGNUM_PLUGINS_DIR_PREFIX ${MAGNUM_LIBRARY_DEBUG} PATH) 283 | set(_MAGNUM_PLUGINS_DIR_SUFFIX "-d") 284 | elseif(MAGNUM_LIBRARY_RELEASE) 285 | set(MAGNUM_LIBRARY ${MAGNUM_LIBRARY_RELEASE}) 286 | get_filename_component(_MAGNUM_PLUGINS_DIR_PREFIX ${MAGNUM_LIBRARY_RELEASE} PATH) 287 | endif() 288 | 289 | # On DLL platforms the plugins are stored in bin/ instead of lib/, modify 290 | # _MAGNUM_PLUGINS_DIR_PREFIX accordingly 291 | if(CORRADE_TARGET_WINDOWS) 292 | get_filename_component(_MAGNUM_PLUGINS_DIR_PREFIX ${_MAGNUM_PLUGINS_DIR_PREFIX} PATH) 293 | set(_MAGNUM_PLUGINS_DIR_PREFIX ${_MAGNUM_PLUGINS_DIR_PREFIX}/bin) 294 | endif() 295 | 296 | if(MAGNUM_LIBRARY_RELEASE) 297 | set_property(TARGET Magnum::Magnum APPEND PROPERTY 298 | IMPORTED_CONFIGURATIONS RELEASE) 299 | set_property(TARGET Magnum::Magnum PROPERTY 300 | IMPORTED_LOCATION_RELEASE ${MAGNUM_LIBRARY_RELEASE}) 301 | endif() 302 | 303 | if(MAGNUM_LIBRARY_DEBUG) 304 | set_property(TARGET Magnum::Magnum APPEND PROPERTY 305 | IMPORTED_CONFIGURATIONS DEBUG) 306 | set_property(TARGET Magnum::Magnum PROPERTY 307 | IMPORTED_LOCATION_DEBUG ${MAGNUM_LIBRARY_DEBUG}) 308 | endif() 309 | 310 | # Include directories 311 | set_property(TARGET Magnum::Magnum APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES 312 | ${MAGNUM_INCLUDE_DIR}) 313 | # Some deprecated APIs use headers (but not externally defined symbols) 314 | # from the GL library, link those includes as well 315 | if(MAGNUM_BUILD_DEPRECATED AND MAGNUM_TARGET_GL) 316 | set_property(TARGET Magnum::Magnum APPEND PROPERTY 317 | INTERFACE_INCLUDE_DIRECTORIES ${MAGNUM_INCLUDE_DIR}/MagnumExternal/OpenGL) 318 | endif() 319 | 320 | # Dependent libraries 321 | set_property(TARGET Magnum::Magnum APPEND PROPERTY INTERFACE_LINK_LIBRARIES 322 | Corrade::Utility) 323 | else() 324 | set(MAGNUM_LIBRARY Magnum::Magnum) 325 | endif() 326 | 327 | # Component distinction (listing them explicitly to avoid mistakes with finding 328 | # components from other repositories) 329 | set(_MAGNUM_LIBRARY_COMPONENT_LIST 330 | Audio DebugTools GL MeshTools Primitives SceneGraph Shaders Text 331 | TextureTools Trade Vk 332 | AndroidApplication GlfwApplication GlutApplication GlxApplication 333 | Sdl2Application XEglApplication WindowlessCglApplication 334 | WindowlessEglApplication WindowlessGlxApplication WindowlessIosApplication WindowlessWglApplication WindowlessWindowsEglApplication 335 | CglContext EglContext GlxContext WglContext 336 | OpenGLTester) 337 | if(MAGNUM_BUILD_DEPRECATED) 338 | list(APPEND _MAGNUM_LIBRARY_COMPONENT_LIST Shapes) 339 | endif() 340 | set(_MAGNUM_PLUGIN_COMPONENT_LIST 341 | AnyAudioImporter AnyImageConverter AnyImageImporter AnySceneImporter 342 | MagnumFont MagnumFontConverter ObjImporter TgaImageConverter TgaImporter 343 | WavAudioImporter) 344 | set(_MAGNUM_EXECUTABLE_COMPONENT_LIST 345 | distancefieldconverter fontconverter imageconverter gl-info al-info) 346 | 347 | # Inter-component dependencies 348 | set(_MAGNUM_Audio_DEPENDENCIES ) 349 | 350 | set(_MAGNUM_DebugTools_DEPENDENCIES ) 351 | if(MAGNUM_TARGET_GL) 352 | # MeshTools, Primitives, SceneGraph, Shaders and Shapes are used only for 353 | # GL renderers. All of this is optional, compiled in only if the base 354 | # library was selected. 355 | list(APPEND _MAGNUM_DebugTools_DEPENDENCIES MeshTools Primitives SceneGraph Shaders Trade GL) 356 | set(_MAGNUM_DebugTools_MeshTools_DEPENDENCY_IS_OPTIONAL ON) 357 | set(_MAGNUM_DebugTools_Primitives_DEPENDENCY_IS_OPTIONAL ON) 358 | set(_MAGNUM_DebugTools_SceneGraph_DEPENDENCY_IS_OPTIONAL ON) 359 | set(_MAGNUM_DebugTools_Shaders_DEPENDENCY_IS_OPTIONAL ON) 360 | set(_MAGNUM_DebugTools_Trade_DEPENDENCY_IS_OPTIONAL ON) 361 | set(_MAGNUM_DebugTools_GL_DEPENDENCY_IS_OPTIONAL ON) 362 | if(MAGNUM_BUILD_DEPRECATED) 363 | list(APPEND _MAGNUM_DebugTools_DEPENDENCIES Shapes) 364 | set(_MAGNUM_DebugTools_Shapes_DEPENDENCY_IS_OPTIONAL ON) 365 | endif() 366 | endif() 367 | 368 | set(_MAGNUM_MeshTools_DEPENDENCIES ) 369 | if(MAGNUM_TARGET_GL) 370 | # Trade is used only in compile(), which needs GL as well 371 | list(APPEND _MAGNUM_MeshTools_DEPENDENCIES Trade GL) 372 | endif() 373 | 374 | set(_MAGNUM_OpenGLTester_DEPENDENCIES GL) 375 | if(MAGNUM_TARGET_HEADLESS OR CORRADE_TARGET_EMSCRIPTEN OR CORRADE_TARGET_ANDROID) 376 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessEglApplication) 377 | elseif(CORRADE_TARGET_IOS) 378 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessIosApplication) 379 | elseif(CORRADE_TARGET_APPLE) 380 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessCglApplication) 381 | elseif(CORRADE_TARGET_UNIX) 382 | if(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_DESKTOP_GLES) 383 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessEglApplication) 384 | else() 385 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessGlxApplication) 386 | endif() 387 | elseif(CORRADE_TARGET_WINDOWS) 388 | if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES) 389 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessWglApplication) 390 | else() 391 | list(APPEND _MAGNUM_OpenGLTester_DEPENDENCIES WindowlessWindowsEglApplication) 392 | endif() 393 | endif() 394 | 395 | set(_MAGNUM_Primitives_DEPENDENCIES Trade) 396 | set(_MAGNUM_SceneGraph_DEPENDENCIES ) 397 | set(_MAGNUM_Shaders_DEPENDENCIES GL) 398 | if(MAGNUM_BUILD_DEPRECATED) 399 | set(_MAGNUM_Shapes_DEPENDENCIES SceneGraph) 400 | endif() 401 | set(_MAGNUM_Text_DEPENDENCIES TextureTools GL) 402 | 403 | set(_MAGNUM_TextureTools_DEPENDENCIES ) 404 | if(MAGNUM_TARGET_GL) 405 | list(APPEND _MAGNUM_TextureTools_DEPENDENCIES GL) 406 | endif() 407 | 408 | set(_MAGNUM_Trade_DEPENDENCIES ) 409 | set(_MAGNUM_AndroidApplication_DEPENDENCIES GL) 410 | 411 | set(_MAGNUM_GlfwApplication_DEPENDENCIES ) 412 | if(MAGNUM_TARGET_GL) 413 | list(APPEND _MAGNUM_GlfwApplication_DEPENDENCIES GL) 414 | endif() 415 | 416 | set(_MAGNUM_GlutApplication_DEPENDENCIES GL) 417 | set(_MAGNUM_GlxApplication_DEPENDENCIES GL) 418 | 419 | set(_MAGNUM_Sdl2Application_DEPENDENCIES ) 420 | if(MAGNUM_TARGET_GL) 421 | list(APPEND _MAGNUM_Sdl2Application_DEPENDENCIES GL) 422 | endif() 423 | 424 | set(_MAGNUM_WindowlessCglApplication_DEPENDENCIES GL) 425 | set(_MAGNUM_WindowlessEglApplication_DEPENDENCIES GL) 426 | set(_MAGNUM_WindowlessGlxApplication_DEPENDENCIES GL) 427 | set(_MAGNUM_WindowlessIosApplication_DEPENDENCIES GL) 428 | set(_MAGNUM_WindowlessWglApplication_DEPENDENCIES GL) 429 | set(_MAGNUM_WindowlessWindowsEglApplication_DEPENDENCIES GL) 430 | set(_MAGNUM_XEglApplication_DEPENDENCIES GL) 431 | set(_MAGNUM_CglContext_DEPENDENCIES GL) 432 | set(_MAGNUM_EglContext_DEPENDENCIES GL) 433 | set(_MAGNUM_GlxContext_DEPENDENCIES GL) 434 | set(_MAGNUM_WglContext_DEPENDENCIES GL) 435 | 436 | set(_MAGNUM_MagnumFont_DEPENDENCIES Trade TgaImporter) # and below 437 | set(_MAGNUM_MagnumFontConverter_DEPENDENCIES Trade TgaImageConverter) # and below 438 | set(_MAGNUM_ObjImporter_DEPENDENCIES MeshTools) # and below 439 | foreach(_component ${_MAGNUM_PLUGIN_COMPONENT_LIST}) 440 | if(_component MATCHES ".+AudioImporter") 441 | list(APPEND _MAGNUM_${_component}_DEPENDENCIES Audio) 442 | elseif(_component MATCHES ".+(Importer|ImageConverter)") 443 | list(APPEND _MAGNUM_${_component}_DEPENDENCIES Trade) 444 | elseif(_component MATCHES ".+(Font|FontConverter)") 445 | list(APPEND _MAGNUM_${_component}_DEPENDENCIES Text TextureTools GL) 446 | endif() 447 | endforeach() 448 | 449 | # Ensure that all inter-component dependencies are specified as well 450 | set(_MAGNUM_ADDITIONAL_COMPONENTS ) 451 | foreach(_component ${Magnum_FIND_COMPONENTS}) 452 | # Mark the dependencies as required if the component is also required, but 453 | # only if they themselves are not optional (for example parts of DebugTools 454 | # are present only if their respective base library is compiled) 455 | if(Magnum_FIND_REQUIRED_${_component}) 456 | foreach(_dependency ${_MAGNUM_${_component}_DEPENDENCIES}) 457 | if(NOT _MAGNUM_${_component}_${_dependency}_DEPENDENCY_IS_OPTIONAL) 458 | set(Magnum_FIND_REQUIRED_${_dependency} TRUE) 459 | endif() 460 | endforeach() 461 | endif() 462 | 463 | list(APPEND _MAGNUM_ADDITIONAL_COMPONENTS ${_MAGNUM_${_component}_DEPENDENCIES}) 464 | endforeach() 465 | 466 | # Join the lists, remove duplicate components 467 | if(_MAGNUM_ADDITIONAL_COMPONENTS) 468 | list(INSERT Magnum_FIND_COMPONENTS 0 ${_MAGNUM_ADDITIONAL_COMPONENTS}) 469 | endif() 470 | if(Magnum_FIND_COMPONENTS) 471 | list(REMOVE_DUPLICATES Magnum_FIND_COMPONENTS) 472 | endif() 473 | 474 | # Convert components lists to regular expressions so I can use if(MATCHES). 475 | # TODO: Drop this once CMake 3.3 and if(IN_LIST) can be used 476 | foreach(_WHAT LIBRARY PLUGIN EXECUTABLE) 477 | string(REPLACE ";" "|" _MAGNUM_${_WHAT}_COMPONENTS "${_MAGNUM_${_WHAT}_COMPONENT_LIST}") 478 | set(_MAGNUM_${_WHAT}_COMPONENTS "^(${_MAGNUM_${_WHAT}_COMPONENTS})$") 479 | endforeach() 480 | 481 | # Find all components. Maintain a list of components that'll need to have 482 | # their optional dependencies checked. 483 | set(_MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD ) 484 | foreach(_component ${Magnum_FIND_COMPONENTS}) 485 | string(TOUPPER ${_component} _COMPONENT) 486 | 487 | # Create imported target in case the library is found. If the project is 488 | # added as subproject to CMake, the target already exists and all the 489 | # required setup is already done from the build tree. 490 | if(TARGET Magnum::${_component}) 491 | set(Magnum_${_component}_FOUND TRUE) 492 | else() 493 | # Library components 494 | if(_component MATCHES ${_MAGNUM_LIBRARY_COMPONENTS}) 495 | add_library(Magnum::${_component} UNKNOWN IMPORTED) 496 | 497 | # Set library defaults, find the library 498 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/${_component}) 499 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h) 500 | 501 | # Try to find both debug and release version 502 | find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG Magnum${_component}-d) 503 | find_library(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE Magnum${_component}) 504 | mark_as_advanced(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG 505 | MAGNUM_${_COMPONENT}_LIBRARY_RELEASE) 506 | endif() 507 | 508 | # Plugin components 509 | if(_component MATCHES ${_MAGNUM_PLUGIN_COMPONENTS}) 510 | add_library(Magnum::${_component} UNKNOWN IMPORTED) 511 | 512 | # AudioImporter plugin specific name suffixes 513 | if(_component MATCHES ".+AudioImporter$") 514 | set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX audioimporters) 515 | 516 | # Audio importer class is Audio::*Importer, thus we need to 517 | # convert *AudioImporter.h to *Importer.h 518 | string(REPLACE "AudioImporter" "Importer" _MAGNUM_${_COMPONENT}_HEADER_NAME "${_component}") 519 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_MAGNUM_${_COMPONENT}_HEADER_NAME}.h) 520 | 521 | # Importer plugin specific name suffixes 522 | elseif(_component MATCHES ".+Importer$") 523 | set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX importers) 524 | 525 | # Font plugin specific name suffixes 526 | elseif(_component MATCHES ".+Font$") 527 | set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fonts) 528 | 529 | # ImageConverter plugin specific name suffixes 530 | elseif(_component MATCHES ".+ImageConverter$") 531 | set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX imageconverters) 532 | 533 | # FontConverter plugin specific name suffixes 534 | elseif(_component MATCHES ".+FontConverter$") 535 | set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fontconverters) 536 | endif() 537 | 538 | # Don't override the exception for *AudioImporter plugins 539 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX MagnumPlugins/${_component}) 540 | if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES) 541 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h) 542 | endif() 543 | 544 | # Dynamic plugins don't have any prefix (e.g. `lib` on Linux), 545 | # search with empty prefix and then reset that back so we don't 546 | # accidentaly break something else 547 | set(_tmp_prefixes "${CMAKE_FIND_LIBRARY_PREFIXES}") 548 | set(CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES};") 549 | 550 | # Try to find both debug and release version. Dynamic and static 551 | # debug libraries are in different places. 552 | find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG ${_component} 553 | PATH_SUFFIXES magnum-d/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX}) 554 | find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG ${_component}-d 555 | PATH_SUFFIXES magnum/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX}) 556 | find_library(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE ${_component} 557 | PATH_SUFFIXES magnum/${_MAGNUM_${_COMPONENT}_PATH_SUFFIX}) 558 | mark_as_advanced(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG 559 | MAGNUM_${_COMPONENT}_LIBRARY_RELEASE) 560 | 561 | # Reset back 562 | set(CMAKE_FIND_LIBRARY_PREFIXES "${_tmp_prefixes}") 563 | endif() 564 | 565 | # Library location for libraries/plugins 566 | if(_component MATCHES ${_MAGNUM_LIBRARY_COMPONENTS} OR _component MATCHES ${_MAGNUM_PLUGIN_COMPONENTS}) 567 | if(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE) 568 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 569 | IMPORTED_CONFIGURATIONS RELEASE) 570 | set_property(TARGET Magnum::${_component} PROPERTY 571 | IMPORTED_LOCATION_RELEASE ${MAGNUM_${_COMPONENT}_LIBRARY_RELEASE}) 572 | endif() 573 | 574 | if(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG) 575 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 576 | IMPORTED_CONFIGURATIONS DEBUG) 577 | set_property(TARGET Magnum::${_component} PROPERTY 578 | IMPORTED_LOCATION_DEBUG ${MAGNUM_${_COMPONENT}_LIBRARY_DEBUG}) 579 | endif() 580 | endif() 581 | 582 | # Executables 583 | if(_component MATCHES ${_MAGNUM_EXECUTABLE_COMPONENTS}) 584 | add_executable(Magnum::${_component} IMPORTED) 585 | 586 | find_program(MAGNUM_${_COMPONENT}_EXECUTABLE magnum-${_component}) 587 | mark_as_advanced(MAGNUM_${_COMPONENT}_EXECUTABLE) 588 | 589 | if(MAGNUM_${_COMPONENT}_EXECUTABLE) 590 | set_property(TARGET Magnum::${_component} PROPERTY 591 | IMPORTED_LOCATION ${MAGNUM_${_COMPONENT}_EXECUTABLE}) 592 | endif() 593 | endif() 594 | 595 | # Applications 596 | if(_component MATCHES ".+Application") 597 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform) 598 | 599 | # Android application dependencies 600 | if(_component STREQUAL AndroidApplication) 601 | find_package(EGL) 602 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 603 | INTERFACE_LINK_LIBRARIES android EGL::EGL) 604 | 605 | # GLFW application dependencies 606 | elseif(_component STREQUAL GlfwApplication) 607 | find_package(GLFW) 608 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 609 | INTERFACE_LINK_LIBRARIES GLFW::GLFW) 610 | # Use the Foundation framework on Apple to query the DPI awareness 611 | if(CORRADE_TARGET_APPLE) 612 | find_library(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY Foundation) 613 | mark_as_advanced(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY) 614 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 615 | INTERFACE_LINK_LIBRARIES ${_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY}) 616 | # Needed for opt-in DPI queries 617 | elseif(CORRADE_TARGET_UNIX) 618 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 619 | INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) 620 | endif() 621 | 622 | # With GLVND (since CMake 3.11) we need to explicitly link to 623 | # GLX/EGL because libOpenGL doesn't provide it. For EGL we have 624 | # our own EGL find module, which makes things simpler. The 625 | # upstream FindOpenGL is anything but simple. Also can't use 626 | # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is 627 | # *not* found. WTF. 628 | if(MAGNUM_TARGET_GL) 629 | if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES)) 630 | set(OpenGL_GL_PREFERENCE GLVND) 631 | find_package(OpenGL) 632 | if(OPENGL_opengl_LIBRARY) 633 | set_property(TARGET Magnum::${_component} APPEND 634 | PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX) 635 | endif() 636 | elseif(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_DESKTOP_GLES AND NOT CORRADE_TARGET_EMSCRIPTEN) 637 | find_package(EGL) 638 | set_property(TARGET Magnum::${_component} APPEND 639 | PROPERTY INTERFACE_LINK_LIBRARIES EGL::EGL) 640 | endif() 641 | endif() 642 | 643 | # GLUT application dependencies 644 | elseif(_component STREQUAL GlutApplication) 645 | find_package(GLUT) 646 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 647 | INTERFACE_INCLUDE_DIRECTORIES ${GLUT_INCLUDE_DIR}) 648 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 649 | INTERFACE_LINK_LIBRARIES ${GLUT_glut_LIBRARY}) 650 | 651 | # With GLVND (since CMake 3.11) we need to explicitly link to 652 | # GLX because libOpenGL doesn't provide it. Also can't use 653 | # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is 654 | # *not* found. WTF. I don't think GLUT works with EGL, so not 655 | # handling that. 656 | set(OpenGL_GL_PREFERENCE GLVND) 657 | find_package(OpenGL) 658 | if(OPENGL_opengl_LIBRARY) 659 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 660 | INTERFACE_LINK_LIBRARIES OpenGL::GLX) 661 | endif() 662 | 663 | # SDL2 application dependencies 664 | elseif(_component STREQUAL Sdl2Application) 665 | find_package(SDL2) 666 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 667 | INTERFACE_LINK_LIBRARIES SDL2::SDL2) 668 | # Use the Foundation framework on Apple to query the DPI awareness 669 | if(CORRADE_TARGET_APPLE) 670 | find_library(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY Foundation) 671 | mark_as_advanced(_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY) 672 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 673 | INTERFACE_LINK_LIBRARIES ${_MAGNUM_APPLE_FOUNDATION_FRAMEWORK_LIBRARY}) 674 | # Needed for opt-in DPI queries 675 | elseif(CORRADE_TARGET_UNIX) 676 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 677 | INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) 678 | endif() 679 | 680 | # With GLVND (since CMake 3.11) we need to explicitly link to 681 | # GLX/EGL because libOpenGL doesn't provide it. For EGL we have 682 | # our own EGL find module, which makes things simpler. The 683 | # upstream FindOpenGL is anything but simple. Also can't use 684 | # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is 685 | # *not* found. WTF. 686 | if(MAGNUM_TARGET_GL) 687 | if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES)) 688 | set(OpenGL_GL_PREFERENCE GLVND) 689 | find_package(OpenGL) 690 | if(OPENGL_opengl_LIBRARY) 691 | set_property(TARGET Magnum::${_component} APPEND 692 | PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX) 693 | endif() 694 | elseif(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_DESKTOP_GLES AND NOT CORRADE_TARGET_EMSCRIPTEN) 695 | find_package(EGL) 696 | set_property(TARGET Magnum::${_component} APPEND 697 | PROPERTY INTERFACE_LINK_LIBRARIES EGL::EGL) 698 | endif() 699 | endif() 700 | 701 | # (Windowless) GLX application dependencies 702 | elseif(_component STREQUAL GlxApplication OR _component STREQUAL WindowlessGlxApplication) 703 | find_package(X11) 704 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 705 | INTERFACE_INCLUDE_DIRECTORIES ${X11_INCLUDE_DIR}) 706 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 707 | INTERFACE_LINK_LIBRARIES ${X11_LIBRARIES}) 708 | 709 | # With GLVND (since CMake 3.11) we need to explicitly link to 710 | # GLX because libOpenGL doesn't provide it. Also can't use 711 | # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is 712 | # *not* found. WTF. 713 | set(OpenGL_GL_PREFERENCE GLVND) 714 | find_package(OpenGL) 715 | if(OPENGL_opengl_LIBRARY) 716 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 717 | INTERFACE_LINK_LIBRARIES OpenGL::GLX) 718 | endif() 719 | 720 | # Windowless CGL application has no additional dependencies 721 | 722 | # Windowless EGL application dependencies 723 | elseif(_component STREQUAL WindowlessEglApplication) 724 | find_package(EGL) 725 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 726 | INTERFACE_LINK_LIBRARIES EGL::EGL) 727 | 728 | # Windowless iOS application dependencies 729 | elseif(_component STREQUAL WindowlessIosApplication) 730 | # We need to link to Foundation framework to use ObjC 731 | find_library(_MAGNUM_IOS_FOUNDATION_FRAMEWORK_LIBRARY Foundation) 732 | mark_as_advanced(_MAGNUM_IOS_FOUNDATION_FRAMEWORK_LIBRARY) 733 | find_package(EGL) 734 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 735 | INTERFACE_LINK_LIBRARIES EGL::EGL ${_MAGNUM_IOS_FOUNDATION_FRAMEWORK_LIBRARY}) 736 | 737 | # Windowless WGL application has no additional dependencies 738 | 739 | # Windowless Windows/EGL application dependencies 740 | elseif(_component STREQUAL WindowlessWindowsEglApplication) 741 | find_package(EGL) 742 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 743 | INTERFACE_LINK_LIBRARIES EGL::EGL) 744 | 745 | # X/EGL application dependencies 746 | elseif(_component STREQUAL XEglApplication) 747 | find_package(EGL) 748 | find_package(X11) 749 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 750 | INTERFACE_INCLUDE_DIRECTORIES ${X11_INCLUDE_DIR}) 751 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 752 | INTERFACE_LINK_LIBRARIES EGL::EGL ${X11_LIBRARIES}) 753 | endif() 754 | 755 | # Context libraries 756 | elseif(_component MATCHES ".+Context") 757 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform) 758 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES GLContext.h) 759 | 760 | # GLX context dependencies 761 | if(_component STREQUAL GlxContext) 762 | # With GLVND (since CMake 3.11) we need to explicitly link to 763 | # GLX because libOpenGL doesn't provide it. Also can't use 764 | # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is 765 | # *not* found. If GLVND is not used, link to X11 instead. 766 | set(OpenGL_GL_PREFERENCE GLVND) 767 | find_package(OpenGL) 768 | if(OPENGL_opengl_LIBRARY) 769 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 770 | INTERFACE_LINK_LIBRARIES OpenGL::GLX) 771 | else() 772 | find_package(X11) 773 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 774 | INTERFACE_INCLUDE_DIRECTORIES ${X11_INCLUDE_DIR}) 775 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 776 | INTERFACE_LINK_LIBRARIES ${X11_LIBRARIES}) 777 | endif() 778 | 779 | # EGL context dependencies 780 | elseif(_component STREQUAL EglContext) 781 | find_package(EGL) 782 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 783 | INTERFACE_LINK_LIBRARIES EGL::EGL) 784 | endif() 785 | 786 | # No additional dependencies for CGL context 787 | # No additional dependencies for WGL context 788 | 789 | # Audio library 790 | elseif(_component STREQUAL Audio) 791 | find_package(OpenAL) 792 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 793 | INTERFACE_INCLUDE_DIRECTORIES ${OPENAL_INCLUDE_DIR}) 794 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 795 | INTERFACE_LINK_LIBRARIES ${OPENAL_LIBRARY} Corrade::PluginManager) 796 | 797 | # No special setup for DebugTools library 798 | 799 | # GL library 800 | elseif(_component STREQUAL GL) 801 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 802 | INTERFACE_INCLUDE_DIRECTORIES ${MAGNUM_INCLUDE_DIR}/MagnumExternal/OpenGL) 803 | 804 | if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES) 805 | # If the GLVND library (CMake 3.11+) was found, link to the 806 | # imported target. Otherwise (and also on all systems except 807 | # Linux) link to the classic libGL. Can't use 808 | # OpenGL_OpenGL_FOUND, because that one is set also if GLVND is 809 | # *not* found. WTF. 810 | set(OpenGL_GL_PREFERENCE GLVND) 811 | find_package(OpenGL REQUIRED) 812 | if(OPENGL_opengl_LIBRARY) 813 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 814 | INTERFACE_LINK_LIBRARIES OpenGL::OpenGL) 815 | else() 816 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 817 | INTERFACE_LINK_LIBRARIES ${OPENGL_gl_LIBRARY}) 818 | endif() 819 | elseif(MAGNUM_TARGET_GLES2) 820 | find_package(OpenGLES2 REQUIRED) 821 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 822 | INTERFACE_LINK_LIBRARIES OpenGLES2::OpenGLES2) 823 | elseif(MAGNUM_TARGET_GLES3) 824 | find_package(OpenGLES3 REQUIRED) 825 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 826 | INTERFACE_LINK_LIBRARIES OpenGLES3::OpenGLES3) 827 | endif() 828 | 829 | # Emscripten needs a special flag to use WebGL 2 830 | if(CORRADE_TARGET_EMSCRIPTEN AND NOT MAGNUM_TARGET_GLES2) 831 | # TODO: give me INTERFACE_LINK_OPTIONS or something, please 832 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1") 833 | endif() 834 | 835 | # MeshTools library 836 | elseif(_component STREQUAL MeshTools) 837 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h) 838 | 839 | # OpenGLTester library 840 | elseif(_component STREQUAL OpenGLTester) 841 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/GL) 842 | 843 | # Primitives library 844 | elseif(_component STREQUAL Primitives) 845 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h) 846 | 847 | # No special setup for SceneGraph library 848 | # No special setup for Shaders library 849 | # No special setup for Shapes library 850 | 851 | # Text library 852 | elseif(_component STREQUAL Text) 853 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 854 | INTERFACE_LINK_LIBRARIES Corrade::PluginManager) 855 | 856 | # TextureTools library 857 | elseif(_component STREQUAL TextureTools) 858 | set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h) 859 | 860 | # Trade library 861 | elseif(_component STREQUAL Trade) 862 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 863 | INTERFACE_LINK_LIBRARIES Corrade::PluginManager) 864 | 865 | # Vk library 866 | elseif(_component STREQUAL Vk) 867 | set(Vulkan_INCLUDE_DIR ${MAGNUM_INCLUDE_DIR}/MagnumExternal/Vulkan) 868 | find_package(Vulkan REQUIRED) 869 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 870 | INTERFACE_LINK_LIBRARIES Vulkan::Vulkan) 871 | endif() 872 | 873 | # No special setup for AnyAudioImporter plugin 874 | # No special setup for AnyImageConverter plugin 875 | # No special setup for AnyImageImporter plugin 876 | # No special setup for AnySceneImporter plugin 877 | # No special setup for MagnumFont plugin 878 | # No special setup for MagnumFontConverter plugin 879 | # No special setup for ObjImporter plugin 880 | # No special setup for TgaImageConverter plugin 881 | # No special setup for TgaImporter plugin 882 | # No special setup for WavAudioImporter plugin 883 | 884 | # Find library/plugin includes 885 | if(_component MATCHES ${_MAGNUM_LIBRARY_COMPONENTS} OR _component MATCHES ${_MAGNUM_PLUGIN_COMPONENTS}) 886 | find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR 887 | NAMES ${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES} 888 | HINTS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX}) 889 | mark_as_advanced(_MAGNUM_${_COMPONENT}_INCLUDE_DIR) 890 | endif() 891 | 892 | # Automatic import of static plugins. Skip in case the include dir was 893 | # not found -- that'll fail later with a proper message. 894 | if(_component MATCHES ${_MAGNUM_PLUGIN_COMPONENTS} AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR) 895 | # Automatic import of static plugins 896 | file(READ ${_MAGNUM_${_COMPONENT}_INCLUDE_DIR}/configure.h _magnum${_component}Configure) 897 | string(FIND "${_magnum${_component}Configure}" "#define MAGNUM_${_COMPONENT}_BUILD_STATIC" _magnum${_component}_BUILD_STATIC) 898 | if(NOT _magnum${_component}_BUILD_STATIC EQUAL -1) 899 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 900 | INTERFACE_SOURCES ${_MAGNUM_${_COMPONENT}_INCLUDE_DIR}/importStaticPlugin.cpp) 901 | endif() 902 | endif() 903 | 904 | # Link to core Magnum library, add inter-library dependencies. If there 905 | # are optional dependencies, defer adding them to later once we know if 906 | # they were found or not. 907 | if(_component MATCHES ${_MAGNUM_LIBRARY_COMPONENTS} OR _component MATCHES ${_MAGNUM_PLUGIN_COMPONENTS}) 908 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 909 | INTERFACE_LINK_LIBRARIES Magnum::Magnum) 910 | set(_MAGNUM_${component}_OPTIONAL_DEPENDENCIES_TO_ADD ) 911 | foreach(_dependency ${_MAGNUM_${_component}_DEPENDENCIES}) 912 | if(NOT _MAGNUM_${_component}_${_dependency}_DEPENDENCY_IS_OPTIONAL) 913 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 914 | INTERFACE_LINK_LIBRARIES Magnum::${_dependency}) 915 | else() 916 | list(APPEND _MAGNUM_${_component}_OPTIONAL_DEPENDENCIES_TO_ADD 917 | ${_dependency}) 918 | endif() 919 | endforeach() 920 | if(_MAGNUM_${_component}_OPTIONAL_DEPENDENCIES_TO_ADD) 921 | list(APPEND _MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD ${_component}) 922 | endif() 923 | endif() 924 | 925 | # Decide if the library was found 926 | if(((_component MATCHES ${_MAGNUM_LIBRARY_COMPONENTS} OR _component MATCHES ${_MAGNUM_PLUGIN_COMPONENTS}) AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR AND (MAGNUM_${_COMPONENT}_LIBRARY_DEBUG OR MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)) OR (_component MATCHES ${_MAGNUM_EXECUTABLE_COMPONENTS} AND MAGNUM_${_COMPONENT}_EXECUTABLE)) 927 | set(Magnum_${_component}_FOUND TRUE) 928 | else() 929 | set(Magnum_${_component}_FOUND FALSE) 930 | endif() 931 | endif() 932 | 933 | # Global aliases for Windowless*Application, *Application and *Context 934 | # components. If already set, unset them to avoid ambiguity. 935 | if(_component MATCHES "Windowless.+Application") 936 | if(NOT DEFINED _MAGNUM_WINDOWLESSAPPLICATION_ALIAS) 937 | set(_MAGNUM_WINDOWLESSAPPLICATION_ALIAS Magnum::${_component}) 938 | else() 939 | unset(_MAGNUM_WINDOWLESSAPPLICATION_ALIAS) 940 | endif() 941 | elseif(_component MATCHES ".+Application") 942 | if(NOT DEFINED _MAGNUM_APPLICATION_ALIAS) 943 | set(_MAGNUM_APPLICATION_ALIAS Magnum::${_component}) 944 | else() 945 | unset(_MAGNUM_APPLICATION_ALIAS) 946 | endif() 947 | elseif(_component MATCHES ".+Context") 948 | if(NOT DEFINED _MAGNUM_GLCONTEXT_ALIAS) 949 | set(_MAGNUM_GLCONTEXT_ALIAS Magnum::${_component}) 950 | else() 951 | unset(_MAGNUM_GLCONTEXT_ALIAS) 952 | endif() 953 | endif() 954 | endforeach() 955 | 956 | # Emscripten-specific files 957 | if(CORRADE_TARGET_EMSCRIPTEN) 958 | find_file(MAGNUM_EMSCRIPTENAPPLICATION_JS EmscriptenApplication.js 959 | PATH_SUFFIXES share/magnum) 960 | find_file(MAGNUM_WINDOWLESSEMSCRIPTENAPPLICATION_JS WindowlessEmscriptenApplication.js 961 | PATH_SUFFIXES share/magnum) 962 | find_file(MAGNUM_WEBAPPLICATION_CSS WebApplication.css 963 | PATH_SUFFIXES share/magnum) 964 | mark_as_advanced( 965 | MAGNUM_EMSCRIPTENAPPLICATION_JS 966 | MAGNUM_WINDOWLESSEMSCRIPTENAPPLICATION_JS 967 | MAGNUM_WEBAPPLICATION_CSS) 968 | set(MAGNUM_EXTRAS_NEEDED 969 | MAGNUM_EMSCRIPTENAPPLICATION_JS 970 | MAGNUM_WINDOWLESSEMSCRIPTENAPPLICATION_JS 971 | MAGNUM_WEBAPPLICATION_CSS) 972 | endif() 973 | 974 | # Complete the check with also all components 975 | include(FindPackageHandleStandardArgs) 976 | find_package_handle_standard_args(Magnum 977 | REQUIRED_VARS MAGNUM_INCLUDE_DIR MAGNUM_LIBRARY ${MAGNUM_EXTRAS_NEEDED} 978 | HANDLE_COMPONENTS) 979 | 980 | # Components with optional dependencies -- add them once we know if they were 981 | # found or not. 982 | foreach(_component ${_MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD}) 983 | foreach(_dependency ${_MAGNUM_${_component}_OPTIONAL_DEPENDENCIES_TO_ADD}) 984 | if(Magnum_${_dependency}_FOUND) 985 | set_property(TARGET Magnum::${_component} APPEND PROPERTY 986 | INTERFACE_LINK_LIBRARIES Magnum::${_dependency}) 987 | endif() 988 | endforeach() 989 | endforeach() 990 | 991 | # Create Windowless*Application, *Application and *Context aliases 992 | # TODO: ugh why can't I make an alias of IMPORTED target? 993 | if(_MAGNUM_WINDOWLESSAPPLICATION_ALIAS AND NOT TARGET Magnum::WindowlessApplication) 994 | get_target_property(_MAGNUM_WINDOWLESSAPPLICATION_ALIASED_TARGET ${_MAGNUM_WINDOWLESSAPPLICATION_ALIAS} ALIASED_TARGET) 995 | if(_MAGNUM_WINDOWLESSAPPLICATION_ALIASED_TARGET) 996 | add_library(Magnum::WindowlessApplication ALIAS ${_MAGNUM_WINDOWLESSAPPLICATION_ALIASED_TARGET}) 997 | else() 998 | add_library(Magnum::WindowlessApplication UNKNOWN IMPORTED) 999 | get_target_property(_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_CONFIGURATIONS ${_MAGNUM_WINDOWLESSAPPLICATION_ALIAS} IMPORTED_CONFIGURATIONS) 1000 | get_target_property(_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_LOCATION_RELEASE ${_MAGNUM_WINDOWLESSAPPLICATION_ALIAS} IMPORTED_LOCATION_RELEASE) 1001 | get_target_property(_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_LOCATION_DEBUG ${_MAGNUM_WINDOWLESSAPPLICATION_ALIAS} IMPORTED_LOCATION_DEBUG) 1002 | set_target_properties(Magnum::WindowlessApplication PROPERTIES 1003 | INTERFACE_INCLUDE_DIRECTORIES $ 1004 | INTERFACE_COMPILE_DEFINITIONS $ 1005 | INTERFACE_COMPILE_OPTIONS $ 1006 | INTERFACE_LINK_LIBRARIES $ 1007 | IMPORTED_CONFIGURATIONS "${_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_CONFIGURATIONS}") 1008 | if(_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_LOCATION_RELEASE) 1009 | set_target_properties(Magnum::WindowlessApplication PROPERTIES 1010 | IMPORTED_LOCATION_RELEASE ${_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_LOCATION_RELEASE}) 1011 | endif() 1012 | if(_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_LOCATION_DEBUG) 1013 | set_target_properties(Magnum::WindowlessApplication PROPERTIES 1014 | IMPORTED_LOCATION_DEBUG ${_MAGNUM_WINDOWLESSAPPLICATION_IMPORTED_LOCATION_DEBUG}) 1015 | endif() 1016 | endif() 1017 | # Prevent creating the alias again 1018 | unset(_MAGNUM_WINDOWLESSAPPLICATION_ALIAS) 1019 | endif() 1020 | if(_MAGNUM_APPLICATION_ALIAS AND NOT TARGET Magnum::Application) 1021 | get_target_property(_MAGNUM_APPLICATION_ALIASED_TARGET ${_MAGNUM_APPLICATION_ALIAS} ALIASED_TARGET) 1022 | if(_MAGNUM_APPLICATION_ALIASED_TARGET) 1023 | add_library(Magnum::Application ALIAS ${_MAGNUM_APPLICATION_ALIASED_TARGET}) 1024 | else() 1025 | add_library(Magnum::Application UNKNOWN IMPORTED) 1026 | get_target_property(_MAGNUM_APPLICATION_IMPORTED_CONFIGURATIONS ${_MAGNUM_APPLICATION_ALIAS} IMPORTED_CONFIGURATIONS) 1027 | get_target_property(_MAGNUM_APPLICATION_IMPORTED_LOCATION_RELEASE ${_MAGNUM_APPLICATION_ALIAS} IMPORTED_LOCATION_RELEASE) 1028 | get_target_property(_MAGNUM_APPLICATION_IMPORTED_LOCATION_DEBUG ${_MAGNUM_APPLICATION_ALIAS} IMPORTED_LOCATION_DEBUG) 1029 | set_target_properties(Magnum::Application PROPERTIES 1030 | INTERFACE_INCLUDE_DIRECTORIES $ 1031 | INTERFACE_COMPILE_DEFINITIONS $ 1032 | INTERFACE_COMPILE_OPTIONS $ 1033 | INTERFACE_LINK_LIBRARIES $ 1034 | IMPORTED_CONFIGURATIONS "${_MAGNUM_APPLICATION_IMPORTED_CONFIGURATIONS}") 1035 | if(_MAGNUM_APPLICATION_IMPORTED_LOCATION_RELEASE) 1036 | set_target_properties(Magnum::Application PROPERTIES 1037 | IMPORTED_LOCATION_RELEASE ${_MAGNUM_APPLICATION_IMPORTED_LOCATION_RELEASE}) 1038 | endif() 1039 | if(_MAGNUM_APPLICATION_IMPORTED_LOCATION_DEBUG) 1040 | set_target_properties(Magnum::Application PROPERTIES 1041 | IMPORTED_LOCATION_DEBUG ${_MAGNUM_APPLICATION_IMPORTED_LOCATION_DEBUG}) 1042 | endif() 1043 | endif() 1044 | # Prevent creating the alias again 1045 | unset(_MAGNUM_APPLICATION_ALIAS) 1046 | endif() 1047 | if(_MAGNUM_GLCONTEXT_ALIAS AND NOT TARGET Magnum::GLContext) 1048 | get_target_property(_MAGNUM_GLCONTEXT_ALIASED_TARGET ${_MAGNUM_GLCONTEXT_ALIAS} ALIASED_TARGET) 1049 | if(_MAGNUM_GLCONTEXT_ALIASED_TARGET) 1050 | add_library(Magnum::GLContext ALIAS ${_MAGNUM_GLCONTEXT_ALIASED_TARGET}) 1051 | else() 1052 | add_library(Magnum::GLContext UNKNOWN IMPORTED) 1053 | get_target_property(_MAGNUM_GLCONTEXT_IMPORTED_CONFIGURATIONS ${_MAGNUM_GLCONTEXT_ALIAS} IMPORTED_CONFIGURATIONS) 1054 | get_target_property(_MAGNUM_GLCONTEXT_IMPORTED_LOCATION_RELEASE ${_MAGNUM_GLCONTEXT_ALIAS} IMPORTED_LOCATION_RELEASE) 1055 | get_target_property(_MAGNUM_GLCONTEXT_IMPORTED_LOCATION_DEBUG ${_MAGNUM_GLCONTEXT_ALIAS} IMPORTED_LOCATION_DEBUG) 1056 | set_target_properties(Magnum::GLContext PROPERTIES 1057 | INTERFACE_INCLUDE_DIRECTORIES $ 1058 | INTERFACE_COMPILE_DEFINITIONS $ 1059 | INTERFACE_COMPILE_OPTIONS $ 1060 | INTERFACE_LINK_LIBRARIES $ 1061 | IMPORTED_CONFIGURATIONS "${_MAGNUM_GLCONTEXT_IMPORTED_CONFIGURATIONS}") 1062 | if(_MAGNUM_GLCONTEXT_IMPORTED_LOCATION_RELEASE) 1063 | set_target_properties(Magnum::GLContext PROPERTIES 1064 | IMPORTED_LOCATION_RELEASE ${_MAGNUM_GLCONTEXT_IMPORTED_LOCATION_RELEASE}) 1065 | endif() 1066 | if(_MAGNUM_GLCONTEXT_IMPORTED_LOCATION_DEBUG) 1067 | set_target_properties(Magnum::GLContext PROPERTIES 1068 | IMPORTED_LOCATION_DEBUG ${_MAGNUM_GLCONTEXT_IMPORTED_LOCATION_DEBUG}) 1069 | endif() 1070 | endif() 1071 | # Prevent creating the alias again 1072 | unset(_MAGNUM_GLCONTEXT_ALIAS) 1073 | endif() 1074 | 1075 | # Installation and deploy dirs 1076 | set(MAGNUM_DEPLOY_PREFIX "." 1077 | CACHE STRING "Prefix where to put final application executables") 1078 | set(MAGNUM_INCLUDE_INSTALL_PREFIX "." 1079 | CACHE STRING "Prefix where to put platform-independent include and other files") 1080 | 1081 | include(${CORRADE_LIB_SUFFIX_MODULE}) 1082 | set(MAGNUM_BINARY_INSTALL_DIR bin) 1083 | set(MAGNUM_LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}) 1084 | set(MAGNUM_DATA_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/share/magnum) 1085 | set(MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR ${MAGNUM_BINARY_INSTALL_DIR}/magnum-d) 1086 | set(MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR ${MAGNUM_LIBRARY_INSTALL_DIR}/magnum-d) 1087 | set(MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR ${MAGNUM_BINARY_INSTALL_DIR}/magnum) 1088 | set(MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_LIBRARY_INSTALL_DIR}/magnum) 1089 | set(MAGNUM_PLUGINS_FONT_DEBUG_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}/fonts) 1090 | set(MAGNUM_PLUGINS_FONT_DEBUG_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR}/fonts) 1091 | set(MAGNUM_PLUGINS_FONT_RELEASE_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR}/fonts) 1092 | set(MAGNUM_PLUGINS_FONT_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}/fonts) 1093 | set(MAGNUM_PLUGINS_FONTCONVERTER_DEBUG_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}/fontconverters) 1094 | set(MAGNUM_PLUGINS_FONTCONVERTER_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}/fontconverters) 1095 | set(MAGNUM_PLUGINS_IMAGECONVERTER_DEBUG_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}/imageconverters) 1096 | set(MAGNUM_PLUGINS_IMAGECONVERTER_DEBUG_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR}/imageconverters) 1097 | set(MAGNUM_PLUGINS_IMAGECONVERTER_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}/imageconverters) 1098 | set(MAGNUM_PLUGINS_IMAGECONVERTER_RELEASE_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR}/imageconverters) 1099 | set(MAGNUM_PLUGINS_IMPORTER_DEBUG_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}/importers) 1100 | set(MAGNUM_PLUGINS_IMPORTER_DEBUG_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR}/importers) 1101 | set(MAGNUM_PLUGINS_IMPORTER_RELEASE_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR}/importers) 1102 | set(MAGNUM_PLUGINS_IMPORTER_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}/importers) 1103 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_DEBUG_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_BINARY_INSTALL_DIR}/audioimporters) 1104 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_DEBUG_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_DEBUG_LIBRARY_INSTALL_DIR}/audioimporters) 1105 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_BINARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_BINARY_INSTALL_DIR}/audioimporters) 1106 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_LIBRARY_INSTALL_DIR ${MAGNUM_PLUGINS_RELEASE_LIBRARY_INSTALL_DIR}/audioimporters) 1107 | set(MAGNUM_INCLUDE_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/include/Magnum) 1108 | set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/include/MagnumExternal) 1109 | set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/include/MagnumPlugins) 1110 | 1111 | # Get base plugin directory from main library location. This is *not* PATH, 1112 | # because CMake always converts the path to an absolute location internally, 1113 | # making it impossible to specify relative paths there. Sorry in advance for 1114 | # not having the dir selection button in CMake GUI. 1115 | set(MAGNUM_PLUGINS_DEBUG_DIR ${_MAGNUM_PLUGINS_DIR_PREFIX}/magnum-d 1116 | CACHE STRING "Base directory where to look for Magnum plugins for debug builds") 1117 | set(MAGNUM_PLUGINS_RELEASE_DIR ${_MAGNUM_PLUGINS_DIR_PREFIX}/magnum 1118 | CACHE STRING "Base directory where to look for Magnum plugins for release builds") 1119 | set(MAGNUM_PLUGINS_DIR ${_MAGNUM_PLUGINS_DIR_PREFIX}/magnum${_MAGNUM_PLUGINS_DIR_SUFFIX} 1120 | CACHE STRING "Base directory where to look for Magnum plugins") 1121 | 1122 | # Plugin directories 1123 | set(MAGNUM_PLUGINS_FONT_DIR ${MAGNUM_PLUGINS_DIR}/fonts) 1124 | set(MAGNUM_PLUGINS_FONT_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_DIR}/fonts) 1125 | set(MAGNUM_PLUGINS_FONT_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/fonts) 1126 | set(MAGNUM_PLUGINS_FONTCONVERTER_DIR ${MAGNUM_PLUGINS_DIR}/fontconverters) 1127 | set(MAGNUM_PLUGINS_FONTCONVERTER_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_DIR}/fontconverters) 1128 | set(MAGNUM_PLUGINS_FONTCONVERTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/fontconverters) 1129 | set(MAGNUM_PLUGINS_IMAGECONVERTER_DIR ${MAGNUM_PLUGINS_DIR}/imageconverters) 1130 | set(MAGNUM_PLUGINS_IMAGECONVERTER_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_DIR}/imageconverters) 1131 | set(MAGNUM_PLUGINS_IMAGECONVERTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/imageconverters) 1132 | set(MAGNUM_PLUGINS_IMPORTER_DIR ${MAGNUM_PLUGINS_DIR}/importers) 1133 | set(MAGNUM_PLUGINS_IMPORTER_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_DIR}/importers) 1134 | set(MAGNUM_PLUGINS_IMPORTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/importers) 1135 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_DIR ${MAGNUM_PLUGINS_DIR}/audioimporters) 1136 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_DEBUG_DIR ${MAGNUM_PLUGINS_DEBUG_DIR}/audioimporters) 1137 | set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/audioimporters) 1138 | -------------------------------------------------------------------------------- /demo/modules/FindSDL2.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # Find SDL2 3 | # --------- 4 | # 5 | # Finds the SDL2 library. This module defines: 6 | # 7 | # SDL2_FOUND - True if SDL2 library is found 8 | # SDL2::SDL2 - SDL2 imported target 9 | # 10 | # Additionally these variables are defined for internal usage: 11 | # 12 | # SDL2_LIBRARY_DEBUG - SDL2 debug library, if found 13 | # SDL2_LIBRARY_RELEASE - SDL2 release library, if found 14 | # SDL2_INCLUDE_DIR - Root include dir 15 | # 16 | 17 | # 18 | # This file is part of Magnum. 19 | # 20 | # Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 21 | # Vladimír Vondruš 22 | # Copyright © 2018 Jonathan Hale 23 | # 24 | # Permission is hereby granted, free of charge, to any person obtaining a 25 | # copy of this software and associated documentation files (the "Software"), 26 | # to deal in the Software without restriction, including without limitation 27 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 28 | # and/or sell copies of the Software, and to permit persons to whom the 29 | # Software is furnished to do so, subject to the following conditions: 30 | # 31 | # The above copyright notice and this permission notice shall be included 32 | # in all copies or substantial portions of the Software. 33 | # 34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 37 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 39 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 40 | # DEALINGS IN THE SOFTWARE. 41 | # 42 | 43 | # In Emscripten SDL is linked automatically, thus no need to find the library. 44 | # Also the includes are in SDL subdirectory, not SDL2. 45 | if(CORRADE_TARGET_EMSCRIPTEN) 46 | set(_SDL2_PATH_SUFFIXES SDL) 47 | else() 48 | # Precompiled libraries for Windows are in x86/x64 subdirectories 49 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 50 | set(_SDL_LIBRARY_PATH_SUFFIX lib/x64) 51 | elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) 52 | set(_SDL_LIBRARY_PATH_SUFFIX lib/x86) 53 | endif() 54 | 55 | find_library(SDL2_LIBRARY_RELEASE 56 | # Compiling SDL2 from scratch on macOS creates dead libSDL2.so symlink 57 | # which CMake somehow prefers before the SDL2-2.0.dylib file. Making 58 | # the dylib first so it is preferred. Not sure how this maps to debug 59 | # config though :/ 60 | NAMES SDL2-2.0 SDL2 61 | PATH_SUFFIXES ${_SDL_LIBRARY_PATH_SUFFIX}) 62 | find_library(SDL2_LIBRARY_DEBUG 63 | NAMES SDL2d 64 | PATH_SUFFIXES ${_SDL_LIBRARY_PATH_SUFFIX}) 65 | # FPHSA needs one of the _DEBUG/_RELEASE variables to check that the 66 | # library was found -- using SDL_LIBRARY, which will get populated by 67 | # select_library_configurations() below. 68 | set(SDL2_LIBRARY_NEEDED SDL2_LIBRARY) 69 | set(_SDL2_PATH_SUFFIXES SDL2) 70 | endif() 71 | 72 | include(SelectLibraryConfigurations) 73 | select_library_configurations(SDL2) 74 | 75 | # Include dir 76 | find_path(SDL2_INCLUDE_DIR 77 | # We must search file which is present only in SDL2 and not in SDL1. 78 | # Apparently when both SDL.h and SDL_scancode.h are specified, CMake is 79 | # happy enough that it found SDL.h and doesn't bother about the other. 80 | # 81 | # On macOS, where the includes are not in SDL2/SDL.h form (which would 82 | # solve this issue), but rather SDL2.framework/Headers/SDL.h, CMake might 83 | # find SDL.framework/Headers/SDL.h if SDL1 is installed, which is wrong. 84 | NAMES SDL_scancode.h 85 | PATH_SUFFIXES ${_SDL2_PATH_SUFFIXES}) 86 | 87 | # iOS dependencies 88 | if(CORRADE_TARGET_IOS) 89 | set(_SDL2_FRAMEWORKS 90 | AudioToolbox 91 | AVFoundation 92 | CoreGraphics 93 | CoreMotion 94 | Foundation 95 | GameController 96 | QuartzCore 97 | UIKit) 98 | set(_SDL2_FRAMEWORK_LIBRARIES ) 99 | foreach(framework ${_SDL2_FRAMEWORKS}) 100 | find_library(_SDL2_${framework}_LIBRARY ${framework}) 101 | mark_as_advanced(_SDL2_${framework}_LIBRARY) 102 | list(APPEND _SDL2_FRAMEWORK_LIBRARIES ${_SDL2_${framework}_LIBRARY}) 103 | list(APPEND _SDL2_FRAMEWORK_LIBRARY_NAMES _SDL2_${framework}_LIBRARY) 104 | endforeach() 105 | endif() 106 | 107 | include(FindPackageHandleStandardArgs) 108 | find_package_handle_standard_args("SDL2" DEFAULT_MSG 109 | ${SDL2_LIBRARY_NEEDED} 110 | ${_SDL2_FRAMEWORK_LIBRARY_NAMES} 111 | SDL2_INCLUDE_DIR) 112 | 113 | if(NOT TARGET SDL2::SDL2) 114 | if(SDL2_LIBRARY_NEEDED) 115 | add_library(SDL2::SDL2 UNKNOWN IMPORTED) 116 | 117 | # Work around BUGGY framework support on macOS 118 | # https://cmake.org/Bug/view.php?id=14105 119 | if(CORRADE_TARGET_APPLE AND SDL2_LIBRARY_RELEASE MATCHES "\\.framework$") 120 | set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) 121 | set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE}/SDL2) 122 | else() 123 | if(SDL2_LIBRARY_RELEASE) 124 | set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) 125 | set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE ${SDL2_LIBRARY_RELEASE}) 126 | endif() 127 | 128 | if(SDL2_LIBRARY_DEBUG) 129 | set_property(TARGET SDL2::SDL2 APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) 130 | set_property(TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_DEBUG ${SDL2_LIBRARY_DEBUG}) 131 | endif() 132 | endif() 133 | 134 | # Link additional `dl` and `pthread` libraries required by a static 135 | # build of SDL on Unixy platforms (except Apple, where it is most 136 | # probably some frameworks instead) 137 | if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND SDL2_LIBRARY MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$") 138 | find_package(Threads) 139 | set_property(TARGET SDL2::SDL2 APPEND PROPERTY 140 | INTERFACE_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) 141 | endif() 142 | 143 | # Link frameworks on iOS 144 | if(CORRADE_TARGET_IOS) 145 | set_property(TARGET SDL2::SDL2 APPEND PROPERTY 146 | INTERFACE_LINK_LIBRARIES ${_SDL2_FRAMEWORK_LIBRARIES}) 147 | endif() 148 | 149 | # Link also EGL library, if on ES (and not on WebGL) 150 | if(MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_DESKTOP_GLES AND NOT MAGNUM_TARGET_WEBGL) 151 | find_package(EGL REQUIRED) 152 | set_property(TARGET SDL2::SDL2 APPEND PROPERTY 153 | INTERFACE_LINK_LIBRARIES EGL::EGL) 154 | endif() 155 | else() 156 | add_library(SDL2::SDL2 INTERFACE IMPORTED) 157 | endif() 158 | 159 | set_property(TARGET SDL2::SDL2 PROPERTY 160 | INTERFACE_INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}) 161 | endif() 162 | -------------------------------------------------------------------------------- /demo/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Magnum REQUIRED 2 | GL 3 | Primitives 4 | Shaders 5 | SceneGraph 6 | MeshTools 7 | DebugTools 8 | Sdl2Application) 9 | 10 | set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON) 11 | include_directories(../..) 12 | 13 | add_executable(MyApplication 14 | ../../MathUtils.cpp 15 | ../../TranslateController.cpp 16 | ../../GridRenderer.cpp 17 | ../../LineRenderer.cpp 18 | ../../ThirdPersonCameraController.cpp 19 | MyApplication.cpp) 20 | 21 | target_link_libraries(MyApplication PRIVATE 22 | Magnum::Application 23 | Magnum::GL 24 | Magnum::Magnum 25 | Magnum::Primitives 26 | Magnum::Shaders 27 | Magnum::DebugTools 28 | Magnum::MeshTools 29 | Magnum::SceneGraph) 30 | -------------------------------------------------------------------------------- /demo/src/CubeDrawable.h: -------------------------------------------------------------------------------- 1 | #ifndef CubeDrawable_h 2 | #define CubeDrawable_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace Magnum; 12 | 13 | class CubeDrawable: public SceneGraph::Drawable3D { 14 | public: 15 | explicit CubeDrawable(Object3D& object, SceneGraph::DrawableGroup3D* group): SceneGraph::Drawable3D{object, group} 16 | { 17 | _mesh = MeshTools::compile(Primitives::cubeSolid()); 18 | } 19 | 20 | private: 21 | void draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) override { 22 | using namespace Math::Literals; 23 | 24 | _shader.setDiffuseColor(0xa5c9ea_rgbf) 25 | .setLightPosition(camera.cameraMatrix().transformPoint( 26 | {5.0f, 5.0f, 7.0f})) 27 | .setTransformationMatrix(transformationMatrix) 28 | .setNormalMatrix(transformationMatrix.rotationScaling()) 29 | .setProjectionMatrix(camera.projectionMatrix()); 30 | _mesh.draw(_shader); 31 | } 32 | 33 | GL::Mesh _mesh; 34 | Shaders::Phong _shader; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /demo/src/MyApplication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "CubeDrawable.h" 16 | 17 | using namespace Magnum; 18 | 19 | class MyApplication: public Platform::Application { 20 | public: 21 | explicit MyApplication(const Arguments& arguments); 22 | 23 | private: 24 | void drawEvent() override; 25 | void mouseMoveEvent(MouseMoveEvent& event) override; 26 | void mousePressEvent(MouseEvent& event) override; 27 | void mouseReleaseEvent(MouseEvent& event) override; 28 | 29 | Scene3D _scene; 30 | SceneGraph::DrawableGroup3D _drawables; 31 | Object3D *_cube; 32 | Timeline _timeline; 33 | 34 | TranslateController *_translateController; 35 | ThirdPersonCameraController *_cameraController; 36 | LineRenderer *_lineRenderer; 37 | 38 | DebugTools::ResourceManager _debugManager; 39 | SceneGraph::DrawableGroup3D _debugDrawables; 40 | }; 41 | 42 | MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments, Configuration{}.setSize({1280,1024}), GLConfiguration{}.setSampleCount(4)} { 43 | GL::Renderer::enable(GL::Renderer::Feature::FaceCulling); 44 | 45 | /* Configure camera */ 46 | _cameraController = new ThirdPersonCameraController{_scene}; 47 | _cameraController->camera() 48 | .setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend) 49 | .setProjectionMatrix(Matrix4::perspectiveProjection(Deg(60.0f), 4.0f/3.0f, 0.01f, 200.0f)) 50 | .setViewport(GL::defaultFramebuffer.viewport().size()); 51 | 52 | /* Demo scene */ 53 | _translateController = new TranslateController{&_scene, &_debugDrawables}; 54 | 55 | _cube = new Object3D{_translateController}; 56 | _cube->scale(Vector3(0.25)); 57 | new CubeDrawable{*_cube, &_drawables}; 58 | 59 | new GridRenderer{_scene, &_drawables}; 60 | 61 | _lineRenderer = new LineRenderer{_scene, &_debugDrawables}; 62 | 63 | // static lines (from, to, color) 64 | _lineRenderer->add({ 2, 0, 2 }, { 3, 0, 3 }, { 1, 0, 0 }); 65 | _lineRenderer->add({ 2, 0, 2 }, { 3, 1, 3 }, { 0, 1, 0 }); 66 | // TODO: bug, dont use Matrix4::lookAt 67 | _lineRenderer->add({ 3, 0, 3 }, { 3, 1, 3 }, { 0, 0, 1 }); 68 | 69 | _timeline.start(); 70 | } 71 | 72 | void MyApplication::drawEvent() { 73 | GL::defaultFramebuffer.clear(GL::FramebufferClear::Color | GL::FramebufferClear::Depth); 74 | 75 | GL::Renderer::enable(GL::Renderer::Feature::DepthTest); 76 | _cameraController->camera().draw(_drawables); 77 | GL::Renderer::disable(GL::Renderer::Feature::DepthTest); 78 | 79 | _cameraController->camera().draw(_debugDrawables); 80 | 81 | swapBuffers(); 82 | redraw(); 83 | 84 | _timeline.nextFrame(); 85 | } 86 | 87 | void MyApplication::mouseMoveEvent(MouseMoveEvent& event) { 88 | if (event.buttons() == MouseMoveEvent::Button::Right) { 89 | _cameraController->move(event.relativePosition()); 90 | return; 91 | } 92 | 93 | if (event.buttons() == MouseMoveEvent::Button::Left) { 94 | Vector2 screenPoint = Vector2{event.position()} / Vector2{windowSize()}; 95 | Ray cameraRay = getCameraToViewportRay(_cameraController->camera(), screenPoint); 96 | 97 | _translateController->move(cameraRay); 98 | } 99 | } 100 | 101 | void MyApplication::mousePressEvent(MouseEvent& event) { 102 | if (event.button() == MouseEvent::Button::Left) { 103 | Vector2 screenPoint = Vector2{event.position()} / Vector2{windowSize()}; 104 | Ray cameraRay = getCameraToViewportRay(_cameraController->camera(), screenPoint); 105 | 106 | _translateController->grab(cameraRay); 107 | } 108 | } 109 | 110 | void MyApplication::mouseReleaseEvent(MouseEvent& event) { 111 | if (event.button() == MouseEvent::Button::Left) { 112 | _translateController->release(); 113 | } 114 | } 115 | 116 | MAGNUM_APPLICATION_MAIN(MyApplication) 117 | --------------------------------------------------------------------------------