diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index 84588d4ab9..ba39b638b5 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -6,6 +6,7 @@ #include +#include #include #include @@ -90,8 +91,8 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs): _offlineCollect(offlineCollect), _statsWidth(1280.0f), _statsHeight(1024.0f), - _font(""), - _characterSize(18.0f) + _characterSize(18.0f), + _VFS(vfs) { _camera = new osg::Camera; _camera->getOrCreateStateSet()->setGlobalDefaults(); @@ -99,11 +100,6 @@ StatsHandler::StatsHandler(bool offlineCollect, VFS::Manager* vfs): _camera->setProjectionResizePolicy(osg::Camera::FIXED); _resourceStatsChildNum = 0; - - if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && vfs->exists(sFontName)) - { - _font = vfs->getAbsoluteFileName(sFontName); - } } Profiler::Profiler(bool offlineCollect, VFS::Manager* vfs): @@ -431,7 +427,6 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) osg::ref_ptr staticText = new osgText::Text; group->addChild( staticText.get() ); staticText->setColor(staticTextColor); - staticText->setFont(_font); staticText->setCharacterSize(_characterSize); staticText->setPosition(pos); @@ -457,11 +452,19 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) group->addChild( statsText.get() ); statsText->setColor(dynamicTextColor); - statsText->setFont(_font); statsText->setCharacterSize(_characterSize); statsText->setPosition(pos); statsText->setText(""); statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames)); + + if (osgDB::Registry::instance()->getReaderWriterForExtension("ttf") && _VFS->exists(sFontName)) + { + Files::IStreamPtr streamPtr = _VFS->get(sFontName); + osg::ref_ptr font = osgText::readRefFontStream(*streamPtr.get()); + + staticText->setFont(font); + statsText->setFont(font); + } } } diff --git a/components/resource/stats.hpp b/components/resource/stats.hpp index b61280ceb1..bb6cf09eda 100644 --- a/components/resource/stats.hpp +++ b/components/resource/stats.hpp @@ -61,11 +61,11 @@ namespace Resource float _statsWidth; float _statsHeight; - std::string _font; float _characterSize; int _resourceStatsChildNum; + VFS::Manager* _VFS; }; void CollectStatistics(osgViewer::ViewerBase* viewer);