diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1ebc524..fc7cb3c98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -272,7 +272,8 @@ endif () endif(OGRE_STATIC) include_directories("." - ${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE ${OGRE_INCLUDE_DIRS} ${OGRE_PLUGIN_INCLUDE_DIRS} ${OGRE_INCLUDE_DIR}/Overlay + ${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE ${OGRE_INCLUDE_DIRS} ${OGRE_PLUGIN_INCLUDE_DIRS} + ${OGRE_INCLUDE_DIR}/Ogre/Overlay ${OGRE_INCLUDE_DIR}/OGRE/Overlay ${OGRE_Overlay_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR} diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 4514aa57e..b58100a08 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -8,13 +8,13 @@ #include #include #include -#include -#include +#include +#include #include #include #include -#include "../../../../components/esm/loadland.hpp" +#include #include "textoverlay.hpp" #include "../../model/world/tablemimedata.hpp" @@ -195,24 +195,13 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event void CSVRender::PagedWorldspaceWidget::updateOverlay() { - Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton(); - Ogre::Overlay* overlay = overlayMgr.getByName("CellIDPanel"); - if(overlay && !mTextOverlays.empty()) + if(getCamera()->getViewport()) { - if(getCamera()->getViewport()) - { - if((uint32_t)getCamera()->getViewport()->getVisibilityMask() - & (uint32_t)CSVRender::Element_CellMarker) - { - mDisplayCellCoord = true; - overlay->show(); - } - else - { - mDisplayCellCoord = false; - overlay->hide(); - } - } + if((uint32_t)getCamera()->getViewport()->getVisibilityMask() + & (uint32_t)CSVRender::Element_CellMarker) + mDisplayCellCoord = true; + else + mDisplayCellCoord = false; } if(!mTextOverlays.empty()) @@ -220,6 +209,7 @@ void CSVRender::PagedWorldspaceWidget::updateOverlay() std::map::iterator it = mTextOverlays.begin(); for(; it != mTextOverlays.end(); ++it) { + it->second->enable(mDisplayCellCoord); it->second->update(); } } @@ -324,14 +314,21 @@ CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget() { delete iter->second; - std::map::iterator it = mEntities.find(iter->first); - if(it != mEntities.end()) - { - getSceneManager()->destroyEntity(it->second); - mEntities.erase(it); - } getSceneManager()->destroyManualObject("manual"+iter->first.getId(mWorldspace)); } + + for (std::map::iterator iter (mEntities.begin()); + iter != mEntities.end(); ++iter) + { + getSceneManager()->destroyEntity(iter->second); + mEntities.erase(iter); + } + + for (std::map::iterator iter (mTextOverlays.begin()); + iter != mTextOverlays.end(); ++iter) + { + delete iter->second; + } } void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint) diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 42d3ae36a..15471d655 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "../widget/scenetoolmode.hpp" #include "../../model/settings/usersettings.hpp" @@ -21,6 +21,8 @@ namespace CSVRender { + Ogre::OverlaySystem *SceneWidget::mOverlaySystem = NULL; + SceneWidget::SceneWidget(QWidget *parent) : QWidget(parent) , mCamera(NULL) @@ -60,7 +62,8 @@ namespace CSVRender setLighting (&mLightingDay); - Ogre::OverlaySystem *mOverlaySystem = new Ogre::OverlaySystem(); + if(!mOverlaySystem) + mOverlaySystem = new Ogre::OverlaySystem(); mSceneMgr->addRenderQueueListener(mOverlaySystem); QTimer *timer = new QTimer (this); @@ -164,11 +167,8 @@ namespace CSVRender if (mWindow) Ogre::Root::getSingleton().destroyRenderTarget (mWindow); - if (mOverlaySystem) - { - if (mSceneMgr) - mSceneMgr->removeRenderQueueListener (mOverlaySystem); - } + if (mSceneMgr) + mSceneMgr->removeRenderQueueListener (mOverlaySystem); if (mSceneMgr) Ogre::Root::getSingleton().destroySceneManager (mSceneMgr); diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index 05d5c7621..07804007a 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -90,7 +90,7 @@ namespace CSVRender Ogre::SceneManager* mSceneMgr; Ogre::RenderWindow* mWindow; Ogre::Viewport *mViewport; - Ogre::OverlaySystem *mOverlaySystem; + static Ogre::OverlaySystem *mOverlaySystem; Navigation *mNavigation; Lighting *mLighting; diff --git a/apps/opencs/view/render/textoverlay.cpp b/apps/opencs/view/render/textoverlay.cpp index 117a57193..d26dda507 100644 --- a/apps/opencs/view/render/textoverlay.cpp +++ b/apps/opencs/view/render/textoverlay.cpp @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -27,18 +27,19 @@ namespace CSVRender // http://www.ogre3d.org/tikiwiki/Creating+dynamic+textures // http://www.ogre3d.org/tikiwiki/ManualObject TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* camera, const Ogre::String& id) - : mOverlay(0), mCaption(""), mDesc(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id), mOnScreen(false) - , mFontHeight(16) // FIXME: make font height configurable + : mOverlay(0), mCaption(""), mDesc(""), mEnabled(true), mCamera(camera), mObj(obj), mId(id) + , mOnScreen(false) , mInstance(0), mFontHeight(16) // FIXME: make font height configurable { if(id == "" || !camera || !obj) throw std::runtime_error("TextOverlay could not be created."); // setup font - if (Ogre::FontManager::getSingleton().resourceExists("DejaVuLGC")) - mFont = Ogre::FontManager::getSingleton().getByName("DejaVuLGC","General"); + Ogre::FontManager &fontMgr = Ogre::FontManager::getSingleton(); + if (fontMgr.resourceExists("DejaVuLGC")) + mFont = fontMgr.getByName("DejaVuLGC","General"); else { - mFont = Ogre::FontManager::getSingleton().create("DejaVuLGC","General"); + mFont = fontMgr.create("DejaVuLGC","General"); mFont->setType(Ogre::FT_TRUETYPE); mFont->setSource("DejaVuLGCSansMono.ttf"); mFont->setTrueTypeSize(mFontHeight); @@ -51,9 +52,13 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam // setup overlay Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton(); - mOverlay = overlayMgr.getByName("CellIDPanel"); - if(!mOverlay) - mOverlay = overlayMgr.create("CellIDPanel"); + mOverlay = overlayMgr.getByName("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance)); + while(mOverlay != NULL) + { + mInstance++; + mOverlay = overlayMgr.getByName("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance)); + } + mOverlay = overlayMgr.create("CellIDPanel"+mId+Ogre::StringConverter::toString(mInstance)); // create texture Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTransBlue"); @@ -93,24 +98,32 @@ TextOverlay::TextOverlay(const Ogre::MovableObject* obj, const Ogre::Camera* cam } // setup material for containers - Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().create("TransOverlayMaterial", - Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true ); - Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 ); - pass->setLightingEnabled( false ); - pass->setDepthWriteEnabled( false ); - pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ); - - Ogre::TextureUnitState *tex = pass->createTextureUnitState("MyCustomState", 0); - tex->setTextureName("DynamicTransBlue"); - tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC ); - mQuadMaterial->load(); - - mContainer = static_cast(overlayMgr.createOverlayElement("Panel", "container"+mId)); + Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().getByName( + "TransOverlayMaterial"); + if(mQuadMaterial.isNull()) + { + Ogre::MaterialPtr mQuadMaterial = Ogre::MaterialManager::getSingleton().create( + "TransOverlayMaterial", + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true ); + Ogre::Pass *pass = mQuadMaterial->getTechnique( 0 )->getPass( 0 ); + pass->setLightingEnabled( false ); + pass->setDepthWriteEnabled( false ); + pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ); + + Ogre::TextureUnitState *tex = pass->createTextureUnitState("MyCustomState", 0); + tex->setTextureName("DynamicTransBlue"); + tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC ); + mQuadMaterial->load(); + } + + mContainer = static_cast(overlayMgr.createOverlayElement( + "Panel", "container"+mId +"#"+Ogre::StringConverter::toString(mInstance))); mContainer->setMaterialName("TransOverlayMaterial"); mOverlay->add2D(mContainer); // setup text area overlay element - mElement = static_cast(overlayMgr.createOverlayElement("TextArea", "text"+mId)); + mElement = static_cast(overlayMgr.createOverlayElement( + "TextArea", "text"+mId +"#"+Ogre::StringConverter::toString(mInstance))); mElement->setMetricsMode(Ogre::GMM_RELATIVE); mElement->setDimensions(1.0, 1.0); mElement->setMetricsMode(Ogre::GMM_PIXELS); @@ -197,10 +210,8 @@ TextOverlay::~TextOverlay() mOverlay->hide(); Ogre::OverlayManager *overlayMgr = Ogre::OverlayManager::getSingletonPtr(); - mContainer->removeChild("text"+mId); + mContainer->removeChild("text"+mId+"#"+Ogre::StringConverter::toString(mInstance)); mOverlay->remove2D(mContainer); - overlayMgr->destroyOverlayElement(mElement); - overlayMgr->destroyOverlayElement(mContainer); if(!iter.hasMoreElements()) overlayMgr->destroy(mOverlay); @@ -208,14 +219,14 @@ TextOverlay::~TextOverlay() void TextOverlay::enable(bool enable) { - if(enable == mContainer->isVisible()) + if(enable == mOverlay->isVisible()) return; mEnabled = enable; if (enable) - mContainer->show(); + mOverlay->show(); else - mContainer->hide(); + mOverlay->hide(); } bool TextOverlay::isEnabled() @@ -282,7 +293,6 @@ void TextOverlay::update() { mOnScreen = false; mContainer->hide(); - Ogre::Root::getSingleton().renderOneFrame(); return; } @@ -306,8 +316,6 @@ void TextOverlay::update() mContainer->setDimensions(relTextWidth, relTextHeight); mPos = QRect(posX*viewportWidth, posY*viewportHeight, width, height); - - Ogre::Root::getSingleton().renderOneFrame(); } QRect TextOverlay::container() diff --git a/apps/opencs/view/render/textoverlay.hpp b/apps/opencs/view/render/textoverlay.hpp index 17530a010..75c5ba2ed 100644 --- a/apps/opencs/view/render/textoverlay.hpp +++ b/apps/opencs/view/render/textoverlay.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include namespace Ogre { @@ -36,6 +36,7 @@ namespace CSVRender bool mEnabled; bool mOnScreen; // not used + int mInstance; Ogre::FontPtr getFont(); int textWidth(); diff --git a/cmake/FindOGRE.cmake b/cmake/FindOGRE.cmake index 24a26ccc7..514b25260 100644 --- a/cmake/FindOGRE.cmake +++ b/cmake/FindOGRE.cmake @@ -364,6 +364,9 @@ macro(ogre_find_component COMPONENT HEADER) make_library_set(OGRE_${COMPONENT}_LIBRARY) findpkg_finish(OGRE_${COMPONENT}) if (OGRE_${COMPONENT}_FOUND) + if (OGRE_${COMPONENT}_INCLUDE_DIR) + set(OGRE_${COMPONENT}_INCLUDE_DIRS ${OGRE_${COMPONENT}_INCLUDE_DIR}) + endif() # find binaries if (NOT OGRE_STATIC) if (WIN32)