diff --git a/Core/ViewerBase.cpp b/Core/ViewerBase.cpp index 74eb1e31a4213383c385ac7cc90cc943fbff3654..b2a6ffecc00ef8e01db67772d1a65079c1bc4646 100644 --- a/Core/ViewerBase.cpp +++ b/Core/ViewerBase.cpp @@ -123,8 +123,8 @@ bool ViewerBase::init() } void ViewerBase::addFBO(const std::string &p_fboName, - Texture *p_colorTex, - Texture *p_depthTex, + std::shared_ptr<Texture> p_colorTex, + std::shared_ptr<Texture> p_depthTex, unsigned int p_width, unsigned int p_height) { FboListItem item; diff --git a/Core/ViewerBase.h b/Core/ViewerBase.h index fd93b735dae9fa8a588fe6160946970a8b291bef..a970107c16127dd6246c3f45ed7f8e165cf6f966 100644 --- a/Core/ViewerBase.h +++ b/Core/ViewerBase.h @@ -37,7 +37,7 @@ class SDK; class OpenGLWindowStream; class MetalShader; class FrameBuffer; -class Texture; +struct Texture; enum RenderingStageType { @@ -72,8 +72,8 @@ struct FboListItem { std::string fboName; ///< String identification FrameBuffer* fbo; ///< The FBO pointer - Texture *depthTex; ///< The FBO depth texture pointer - Texture *colorTex; ///< The FBO color texture pointer + std::shared_ptr<Texture> depthTex; ///< The FBO depth texture pointer + std::shared_ptr<Texture> colorTex; ///< The FBO color texture pointer unsigned int width; ///< The width of the FBO unsigned int height; ///< The height of the FBO }; @@ -142,7 +142,8 @@ public: /// \param p_height The height of the fbo void addFBO( const std::string &p_fboName, - Texture *p_colorTex, Texture *p_depthTex, + std::shared_ptr<Texture> p_colorTex, + std::shared_ptr<Texture> p_depthTex, unsigned int p_width, unsigned int p_height); virtual void setGlobalAxisLength(const float len); diff --git a/Examples/common/CMakeLists.txt b/Examples/common/CMakeLists.txt index f0607b9b0adf46c2876a39097044e4b1afe659d7..1c7914efaff1f08cf74740e048988da35b1dd7a0 100644 --- a/Examples/common/CMakeLists.txt +++ b/Examples/common/CMakeLists.txt @@ -8,6 +8,7 @@ list(APPEND ExamplesCommon_sources hapticController.cpp pzrMouseCameraController.cpp ExampleCube.cpp + TexturedSquare.cpp ) list(APPEND ExamplesCommon_headers @@ -16,6 +17,7 @@ list(APPEND ExamplesCommon_headers hapticController.h pzrMouseCameraController.h ExampleCube.h + TexturedSquare.h ) list(APPEND ExamplesCommon_link_libs @@ -23,6 +25,8 @@ list(APPEND ExamplesCommon_link_libs Rendering Event Simulators + Geometry + Mesh ) if(SimMedTK_USE_PHANTOM_OMNI) @@ -47,4 +51,4 @@ simmedtk_add_library(ExamplesCommon target_link_libraries(ExamplesCommon ${ExamplesCommon_link_libs} -) +) \ No newline at end of file diff --git a/Examples/common/ExampleCube.h b/Examples/common/ExampleCube.h index ad16687b5ae8d831c7abfe46958186a7f052e53b..4f3d10b29a25d4e41b1690f3e0d3ae2287f389c7 100644 --- a/Examples/common/ExampleCube.h +++ b/Examples/common/ExampleCube.h @@ -21,6 +21,9 @@ // Contact: //--------------------------------------------------------------------------- +#ifndef MSTK_EXAMPLES_COMMON_EXAMPLECUBE_H +#define MSTK_EXAMPLES_COMMON_EXAMPLECUBE_H + #include <memory> #include "Core/StaticSceneObject.h" @@ -49,3 +52,5 @@ private: } //Common } //Examples } //mstk + +#endif diff --git a/Examples/common/TexturedSquare.cpp b/Examples/common/TexturedSquare.cpp new file mode 100644 index 0000000000000000000000000000000000000000..20b26981f51e7dc0967617090326793ec9263282 --- /dev/null +++ b/Examples/common/TexturedSquare.cpp @@ -0,0 +1,88 @@ +// This file is part of the SimMedTK project. +// Copyright (c) Center for Modeling, Simulation, and Imaging in Medicine, +// Rensselaer Polytechnic Institute +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//--------------------------------------------------------------------------- +// +// Authors: +// +// Contact: +//--------------------------------------------------------------------------- + +#include "TexturedSquare.h" + +#include "Core/Factory.h" +#include "Core/StaticSceneObject.h" +#include "Core/RenderDelegate.h" +#include "Rendering/TextureManager.h" + +namespace mstk { +namespace Examples { +namespace Common { + +TexturedSquare::TexturedSquare(bool vtkRenderer) + : useVTK(vtkRenderer) +{ +} + +void TexturedSquare::useVTKRenderer(bool b) +{ + this->useVTK = b; +} + +std::shared_ptr<StaticSceneObject> TexturedSquare::getStaticSceneObject() +{ + return this->square; +} + +void TexturedSquare::setup() +{ + squareModel = std::make_shared<MeshModel>(); + squareModel->load("models/square.obj"); + + renderDetail = std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); + squareModel->setRenderDetail(renderDetail); + + square = std::make_shared<StaticSceneObject>(); + square->setModel(squareModel); + + // If you want to use the GL renderer you need to specify the appropiate render delegates + // This can be automated in the future, for now VTK is the default renderer and the delegates + // need to be reset. + if(!useVTK) + { + auto renderDelegate = Factory<RenderDelegate>::createConcreteClassForGroup( + "StaticSceneObjectRenderDelegate", RenderDelegate::RendererType::Other); + square->setRenderDelegate(renderDelegate); + + renderDelegate = Factory<RenderDelegate>::createConcreteClassForGroup( + "MeshRenderDelegate", RenderDelegate::RendererType::Other); + squareModel->getMesh()->setRenderDelegate(renderDelegate); + } +} + +void TexturedSquare::setTexture(const std::string &t) +{ + renderDetail->setTextureFilename(t); + + if(!useVTK) + { + std::static_pointer_cast<SurfaceMesh>(squareModel->getMesh())->assignTexture(t); + } +} + +} //Common +} //Examples +} //mstk diff --git a/Examples/common/TexturedSquare.h b/Examples/common/TexturedSquare.h new file mode 100644 index 0000000000000000000000000000000000000000..f969ef34c0c6c1bdb14fc803a0d3490618b9c369 --- /dev/null +++ b/Examples/common/TexturedSquare.h @@ -0,0 +1,59 @@ +// This file is part of the SimMedTK project. +// Copyright (c) Center for Modeling, Simulation, and Imaging in Medicine, +// Rensselaer Polytechnic Institute +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//--------------------------------------------------------------------------- +// +// Authors: +// +// Contact: +//--------------------------------------------------------------------------- + + +#ifndef MSTK_EXAMPLES_COMMON_TEXTUREDSQUARE_H +#define MSTK_EXAMPLES_COMMON_TEXTUREDSQUARE_H + +#include <string> +#include <memory> + +#include "Core/StaticSceneObject.h" +#include "Geometry/MeshModel.h" + +namespace mstk { +namespace Examples { +namespace Common { + +class TexturedSquare +{ +public: + TexturedSquare(bool vtkRenderer = true); + void useVTKRenderer(bool b); + void setup(); + std::shared_ptr<StaticSceneObject> getStaticSceneObject(); + void setTexture(const std::string &t); + +private: + std::shared_ptr<StaticSceneObject> square; + std::shared_ptr<RenderDetail> renderDetail; + std::shared_ptr<MeshModel> squareModel; + + bool useVTK; +}; + +} //Common +} //Examples +} //mstk + +#endif diff --git a/Examples/renderCubeToTexture/CMakeLists.txt b/Examples/renderCubeToTexture/CMakeLists.txt index 0427aaa91035ba36e5c59aa9981a169a8f96788a..fc0058602e3abd8dcd5b9c4424f4a332d73a343f 100644 --- a/Examples/renderCubeToTexture/CMakeLists.txt +++ b/Examples/renderCubeToTexture/CMakeLists.txt @@ -1,11 +1,13 @@ - -add_executable(renderCubeToTexture main.cpp) -target_link_libraries(renderCubeToTexture - Core - Event - Rendering - Mesh - Collision - ExamplesCommon - Geometry - ) + +add_executable(renderCubeToTexture main.cpp) +target_link_libraries(renderCubeToTexture + Core + Rendering + RenderDelegates + IO + Mesh + Event + Collision + ExamplesCommon + Geometry + ) diff --git a/Examples/renderCubeToTexture/main.cpp b/Examples/renderCubeToTexture/main.cpp index 7cda77016287feb4f3b40226780ef1f611f665db..ad9d726d563f29227cb1e42abd60f7abc5f9ade2 100644 --- a/Examples/renderCubeToTexture/main.cpp +++ b/Examples/renderCubeToTexture/main.cpp @@ -21,113 +21,97 @@ // Contact: //--------------------------------------------------------------------------- -#include "../common/wasdCameraController.h" -#include "../common/KeyPressSDKShutdown.h" +#include "Examples/common/wasdCameraController.h" +#include "Examples/common/KeyPressSDKShutdown.h" +#include "Examples/common/pzrMouseCameraController.h" +#include "Examples/common/ExampleCube.h" +#include "Examples/common/TexturedSquare.h" #include <memory> -#include "Core/SDK.h" +#include "IO/initIO.h" +#include "RenderDelegates/initRenderDelegates.h" +#include "VTKRendering/initVTKRendering.h" #include "Rendering/TextureManager.h" -#include "Collision/MeshCollisionModel.h" +#include "Geometry/MeshModel.h" +#include "Core/Factory.h" +#include "Core/ViewerBase.h" int main() { - std::shared_ptr<SDK> sdk; - std::shared_ptr<OpenGLViewer> viewer; - std::shared_ptr<Scene> scene1, scene2; - std::shared_ptr<Light> light1, light2; - std::shared_ptr<Camera> sceneCamera1, sceneCamera2; - std::shared_ptr<StaticSceneObject> cube, square; - std::shared_ptr<mstk::Examples::Common::wasdCameraController> camCtl; - std::shared_ptr<mstk::Examples::Common::KeyPressSDKShutdown> keyShutdown; + using ExampleCube = mstk::Examples::Common::ExampleCube; + using TexturedSquare = mstk::Examples::Common::TexturedSquare; - //Create an instance of the SimMedTK framework/SDK - sdk = SDK::getInstance(); + ExampleCube cube; + TexturedSquare square; - //Create the scenes - scene1 = sdk->createScene(); //internal scene containing cube - scene2 = sdk->createScene(); //external scene containing square with scene1 mapped to it + initRenderDelegates(); + initIODelegates(); - //Create a viewer to see the scene through - viewer = std::make_shared<OpenGLViewer>(); - sdk->addViewer(viewer); + auto scene1 = std::make_shared<Scene>(); + auto scene2 = std::make_shared<Scene>(); - //Create the camera controller - camCtl = std::make_shared<mstk::Examples::Common::wasdCameraController>(); - keyShutdown = std::make_shared<mstk::Examples::Common::KeyPressSDKShutdown>(); + // Create a viewer + auto viewer = Factory<ViewerBase>::createSubclassForGroup("ViewerBase",RenderDelegate::Other); - auto cubeModel = std::make_shared<MeshModel>(); - TextureManager::addTexture("textures/cube.png", "cubetex"); - cubeModel->load("models/cube.obj"); - std::static_pointer_cast<SurfaceMesh>(cubeModel->getMesh())->assignTexture("cubetex"); + assert(viewer); + assert(scene1); + assert(scene2); - auto renderDetail = std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); - cubeModel->setRenderDetail(renderDetail); + cube.useVTKRenderer(false); + cube.setup(); - cube = std::make_shared<StaticSceneObject>(); - cube->setModel(cubeModel); + square.useVTKRenderer(false); + square.setup(); - //Add the cube to the scene to be rendered - scene1->addSceneObject(cube); - - //setup scene2 + //setup scene for displaying the rendered to texture object //Create a color and depth texture for the FBO TextureManager::createColorTexture("colorTex1", 64, 64); TextureManager::createDepthTexture("depthTex1", 64, 64); - std::shared_ptr<MeshModel> squareModel = std::make_shared<MeshModel>(); - squareModel->load("models/square.obj"); - std::static_pointer_cast<SurfaceMesh>(squareModel->getMesh())->assignTexture("colorTex1"); - renderDetail= std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); - squareModel->setRenderDetail(renderDetail); + viewer->addFBO("fbo1", + TextureManager::getTexture("colorTex1"), + TextureManager::getTexture("depthTex1"), + 64, 64); - square = std::make_shared<StaticSceneObject>(); - square->setModel(squareModel); + square.setTexture("colorTex1"); - //Setup an FBO for rendering in the viewer. - //Add the FBO and textures to the viewer - viewer->addFBO("fbo1", - TextureManager::getTexture("colorTex1").get(), - TextureManager::getTexture("depthTex1").get(), - 64, 64); + // Add the cube to the scene to be rendered + scene1->addSceneObject(cube.getStaticSceneObject()); - //Add the square to the scene - scene2->addSceneObject(square); + //Add the square to the scene to be rendered + scene2->addSceneObject(square.getStaticSceneObject()); - //Register the scene with the viewer, and setup render target + // Register the scene with the viewer, and setup render target viewer->registerScene(scene1, SMRENDERTARGET_FBO, "fbo1"); viewer->registerScene(scene2, SMRENDERTARGET_SCREEN, ""); - //Setup the window title in the window manager + // Setup the window title in the window manager viewer->setWindowTitle("SimMedTK RENDER TO TEXTURE TEST"); - //Set some viewer properties + // Set some viewer properties viewer->setScreenResolution(800, 640); - //Uncomment the following line for fullscreen - //viewer->viewerRenderDetail |= SIMMEDTK_VIEWERRENDER_FULLSCREEN; - // Setup Scene lighting - light1 = Light::getDefaultLighting(); + auto light1 = Light::getDefaultLighting(); assert(light1); scene1->addLight(light1); - light2 = Light::getDefaultLighting(); + auto light2 = Light::getDefaultLighting(); assert(light2); light2->lightPos.setPosition(core::Vec3d(0.0, 0.0, 5.0)); scene2->addLight(light2); // Camera setup - sceneCamera1 = Camera::getDefaultCamera(); + auto sceneCamera1 = Camera::getDefaultCamera(); assert(sceneCamera1); sceneCamera1->setPos(3, 3, 5); sceneCamera1->setFocus(0, 0, -1); sceneCamera1->genProjMat(); sceneCamera1->genViewMat(); scene1->addCamera(sceneCamera1); - camCtl->setCamera(sceneCamera1); - sceneCamera2 = Camera::getDefaultCamera(); + auto sceneCamera2 = Camera::getDefaultCamera(); assert(sceneCamera2); sceneCamera2->setPos(0, 0, 5); sceneCamera2->setFocus(0, 0, -1); @@ -135,16 +119,20 @@ int main() sceneCamera2->genViewMat(); scene2->addCamera(sceneCamera2); - //Link up the event system between this the camera controller and the viewer + // Create the camera controller + auto camCtl = std::make_shared<mstk::Examples::Common::wasdCameraController>(); + auto keyShutdown = std::make_shared<mstk::Examples::Common::KeyPressSDKShutdown>(); + auto pzrCamCtl = std::make_shared<mstk::Examples::Common::pzrMouseCameraController>(); + camCtl->setCamera(sceneCamera1); + pzrCamCtl->setCamera(sceneCamera1); + + // Link up the event system between this the camera controller and the viewer viewer->attachEvent(core::EventType::Keyboard, camCtl); viewer->attachEvent(core::EventType::Keyboard, keyShutdown); + viewer->attachEvent(core::EventType::MouseMove, pzrCamCtl); + viewer->attachEvent(core::EventType::MouseButton, pzrCamCtl); - //run the framework - sdk->run(); - - //cleanup - sdk->releaseScene(scene1); - sdk->releaseScene(scene2); + viewer->exec(); return 0; } diff --git a/Examples/renderCubeToTextureOculus/CMakeLists.txt b/Examples/renderCubeToTextureOculus/CMakeLists.txt index d0a622da08f2a0032c6f76c4a5a358dde3df4674..5916dced0e1532e25c83cb36d109569d05bb77e9 100644 --- a/Examples/renderCubeToTextureOculus/CMakeLists.txt +++ b/Examples/renderCubeToTextureOculus/CMakeLists.txt @@ -1,11 +1,14 @@ add_executable(renderCubeToTextureOculus main.cpp) target_link_libraries(renderCubeToTextureOculus Core - Event Rendering RenderingOculus + RenderDelegates + IO Mesh - Geometry + Event + Collision ExamplesCommon + Geometry Oculus::Oculus ) diff --git a/Examples/renderCubeToTextureOculus/main.cpp b/Examples/renderCubeToTextureOculus/main.cpp index a93cfe6c149db8b9bb84ae6eca6030ac55672a67..9198ea853d2fc76891a2c4267cb7fe902dcce8d6 100644 --- a/Examples/renderCubeToTextureOculus/main.cpp +++ b/Examples/renderCubeToTextureOculus/main.cpp @@ -21,125 +21,122 @@ // Contact: //--------------------------------------------------------------------------- -#include "../common/wasdCameraController.h" -#include "../common/KeyPressSDKShutdown.h" +#include "Examples/common/wasdCameraController.h" +#include "Examples/common/KeyPressSDKShutdown.h" +#include "Examples/common/pzrMouseCameraController.h" +#include "Examples/common/ExampleCube.h" +#include "Examples/common/TexturedSquare.h" #include <memory> -#include "Core/SDK.h" +#include "IO/initIO.h" +#include "RenderDelegates/initRenderDelegates.h" +#include "VTKRendering/initVTKRendering.h" #include "Rendering/TextureManager.h" #include "Rendering/OculusViewer.h" -#include "Collision/MeshCollisionModel.h" +#include "Geometry/MeshModel.h" +#include "Core/Factory.h" +#include "Core/ViewerBase.h" int main() { - std::shared_ptr<SDK> sdk; - std::shared_ptr<smOculusViewer> viewer; - std::shared_ptr<Scene> scene1, scene2; - std::shared_ptr<Light> light1, light2; - std::shared_ptr<Camera> sceneCamera1, sceneCamera2; - std::shared_ptr<StaticSceneObject> cube, square; - std::shared_ptr<mstk::Examples::Common::wasdCameraController> camCtl; - std::shared_ptr<mstk::Examples::Common::KeyPressSDKShutdown> keyShutdown; + using ExampleCube = mstk::Examples::Common::ExampleCube; + using TexturedSquare = mstk::Examples::Common::TexturedSquare; - //Create an instance of the SimMedTK framework/SDK - sdk = SDK::getInstance(); + ExampleCube cube; + TexturedSquare square; - //Create the scenes - scene1 = sdk->createScene(); //internal scene containing cube - scene2 = sdk->createScene(); //external scene containing square with scene1 mapped to it + initRenderDelegates(); + initIODelegates(); - //Create a viewer to see the scene through - viewer = std::make_shared<smOculusViewer>(); - sdk->addViewer(viewer); + auto scene1 = std::make_shared<Scene>(); + auto scene2 = std::make_shared<Scene>(); - //Create the camera controller - camCtl = std::make_shared<mstk::Examples::Common::wasdCameraController>(); - keyShutdown = std::make_shared<mstk::Examples::Common::KeyPressSDKShutdown>(); + // Create a viewer + auto viewer = std::make_shared<OculusViewer>(); - auto cubeModel = std::make_shared<MeshModel>(); - cubeModel->load("models/cube.obj", "textures/cube.png", "cubetex"); + assert(viewer); + assert(scene1); + assert(scene2); - auto renderDetail = std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); - cubeModel->setRenderDetail(renderDetail); + cube.useVTKRenderer(false); + cube.setup(); - cube = std::make_shared<StaticSceneObject>(); - cube->setModel(cubeModel); + square.useVTKRenderer(false); + square.setup(); - //Add the cube to the scene to be rendered - scene1->addSceneObject(cube); - - //setup scene2 + //setup scene for displaying the rendered to texture object //Create a color and depth texture for the FBO TextureManager::createColorTexture("colorTex1", 64, 64); TextureManager::createDepthTexture("depthTex1", 64, 64); - std::shared_ptr<MeshModel> squareModel = std::make_shared<MeshModel>(); - squareModel->load("models/square.obj", BaseMesh::MeshFileType::Obj); - squareModel->getMesh()->assignTexture("colorTex1"); - renderDetail= std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); - squareModel->setRenderDetail(renderDetail); + viewer->addFBO("fbo1", + TextureManager::getTexture("colorTex1"), + TextureManager::getTexture("depthTex1"), + 64, 64); - square = std::make_shared<StaticSceneObject>(); - square->setModel(squareModel); + square.setTexture("colorTex1"); - //Setup an FBO for rendering in the viewer. - //Add the FBO and textures to the viewer - viewer->addFBO("fbo1", - TextureManager::getTexture("colorTex1"), - TextureManager::getTexture("depthTex1"), - 64, 64); + // Add the cube to the scene to be rendered + scene1->addSceneObject(cube.getStaticSceneObject()); - //Add the square to the scene - scene2->addSceneObject(square); + //Add the square to the scene to be rendered + scene2->addSceneObject(square.getStaticSceneObject()); - //Register the scene with the viewer, and setup render target + // Register the scene with the viewer, and setup render target viewer->registerScene(scene1, SMRENDERTARGET_FBO, "fbo1"); viewer->registerScene(scene2, SMRENDERTARGET_SCREEN, ""); - //Setup the window title in the window manager + // Setup the window title in the window manager viewer->setWindowTitle("SimMedTK RENDER TO TEXTURE TEST"); - //Set some viewer properties - viewer->setScreenResolution(1920, 1080); + // Set some viewer properties + viewer->setScreenResolution(800, 640); - //Uncomment the following line for fullscreen + //Make the window fullscreen for oculus viewer->viewerRenderDetail |= SIMMEDTK_VIEWERRENDER_FULLSCREEN; // Setup Scene lighting - light1 = Light::getDefaultLighting(); + auto light1 = Light::getDefaultLighting(); assert(light1); scene1->addLight(light1); - light2 = Light::getDefaultLighting(); + auto light2 = Light::getDefaultLighting(); assert(light2); light2->lightPos.setPosition(core::Vec3d(0.0, 0.0, 5.0)); scene2->addLight(light2); // Camera setup - sceneCamera1 = Camera::getDefaultCamera(); + auto sceneCamera1 = Camera::getDefaultCamera(); assert(sceneCamera1); sceneCamera1->setPos(3, 3, 5); sceneCamera1->setFocus(0, 0, -1); + sceneCamera1->genProjMat(); + sceneCamera1->genViewMat(); scene1->addCamera(sceneCamera1); - camCtl->setCamera(sceneCamera1); - sceneCamera2 = Camera::getDefaultCamera(); + auto sceneCamera2 = Camera::getDefaultCamera(); assert(sceneCamera2); sceneCamera2->setPos(0, 0, 5); sceneCamera2->setFocus(0, 0, -1); + sceneCamera2->genProjMat(); + sceneCamera2->genViewMat(); scene2->addCamera(sceneCamera2); - //Link up the event system between this the camera controller and the viewer + // Create the camera controller + auto camCtl = std::make_shared<mstk::Examples::Common::wasdCameraController>(); + auto keyShutdown = std::make_shared<mstk::Examples::Common::KeyPressSDKShutdown>(); + auto pzrCamCtl = std::make_shared<mstk::Examples::Common::pzrMouseCameraController>(); + camCtl->setCamera(sceneCamera1); + pzrCamCtl->setCamera(sceneCamera1); + + // Link up the event system between this the camera controller and the viewer viewer->attachEvent(core::EventType::Keyboard, camCtl); viewer->attachEvent(core::EventType::Keyboard, keyShutdown); + viewer->attachEvent(core::EventType::MouseMove, pzrCamCtl); + viewer->attachEvent(core::EventType::MouseButton, pzrCamCtl); - //run the framework - sdk->run(); - - //cleanup - sdk->releaseScene(scene1); - sdk->releaseScene(scene2); + viewer->exec(); return 0; } diff --git a/Rendering/FrameBuffer.cpp b/Rendering/FrameBuffer.cpp index c2dfbf1422c38b214e633a00bd2968663b8a68c1..32d749fa0c8628602183bd8c856e25d5f36419b9 100644 --- a/Rendering/FrameBuffer.cpp +++ b/Rendering/FrameBuffer.cpp @@ -237,7 +237,7 @@ void FrameBuffer::attachRenderBuffer( RenderBuffer *p_renderBuf ) _fbo.AttachRenderBuffer( p_renderBuf->getRenderBufId(), p_renderBuf->getGLAttachmentId() ); } } -void FrameBuffer::attachDepthTexture( Texture *p_texture ) +void FrameBuffer::attachDepthTexture(std::shared_ptr<Texture> p_texture ) { if ( p_texture == nullptr ) { @@ -247,7 +247,7 @@ void FrameBuffer::attachDepthTexture( Texture *p_texture ) _fbo.AttachTexture( p_texture->GLtype, p_texture->textureGLId, GL_DEPTH_ATTACHMENT_EXT ); isDepthTexAttached = true; } -void FrameBuffer::attachColorTexture( Texture *p_texture, int p_attachmentOrder ) +void FrameBuffer::attachColorTexture(std::shared_ptr<Texture> p_texture, int p_attachmentOrder ) { defaultColorAttachment = p_attachmentOrder; _fbo.AttachTexture( p_texture->GLtype, p_texture->textureGLId, GL_COLOR_ATTACHMENT0_EXT + p_attachmentOrder ); diff --git a/Rendering/FrameBuffer.h b/Rendering/FrameBuffer.h index 06b12bfc6406ce61d442280cdc77693194cc1bf9..f53538e1a779a73d991cb7007cf5a932a0d5a5ff 100644 --- a/Rendering/FrameBuffer.h +++ b/Rendering/FrameBuffer.h @@ -21,8 +21,8 @@ // Contact: //--------------------------------------------------------------------------- -#ifndef SMFRAMEBUFFEROBJECT_H -#define SMFRAMEBUFFEROBJECT_H +#ifndef SMFRAMEBUFFER_H +#define SMFRAMEBUFFER_H // STL includes #include <string> @@ -126,9 +126,9 @@ public: /// \brief attach render buffer to te frame buffer void attachRenderBuffer(RenderBuffer *p_renderBuf); /// \brief attach depth texture - void attachDepthTexture(Texture *p_texture); + void attachDepthTexture(std::shared_ptr<Texture> p_texture); /// \brief attach a color texture - void attachColorTexture(Texture *p_texture, int p_attachmentOrder); + void attachColorTexture(std::shared_ptr<Texture> p_texture, int p_attachmentOrder); /// \brief activate color buffer in the specified order void activeColorBuf(int p_order); /// \brief enable the framebuffer diff --git a/Rendering/OpenGLViewer.cpp b/Rendering/OpenGLViewer.cpp index 29db0b60432053ff86796d4b26b800713ceb0d60..61b5d0149184ae46adfda597421f0ceecb1773ab 100644 --- a/Rendering/OpenGLViewer.cpp +++ b/Rendering/OpenGLViewer.cpp @@ -26,6 +26,7 @@ #include "Core/EventHandler.h" #include "Core/IOStream.h" #include "Core/Factory.h" +#include "Core/ViewerBase.h" #include "Event/KeyboardEvent.h" #include "Event/KeySFMLInterface.h" #include "Event/MouseButtonEvent.h"