diff --git a/include/osgText/Font b/include/osgText/Font index ae00c1ef9..aa9589e24 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -88,6 +88,11 @@ public: virtual std::string getFileName() const; + + void setStateSet(osg::StateSet* stateset) { _stateset = stateset; } + osg::StateSet* getStateSet() { return _stateset.get(); } + const osg::StateSet* getStateSet() const { return _stateset.get(); } + /** Set the pixel width and height hint.*/ virtual void setFontResolution(unsigned int width, unsigned int height); @@ -152,6 +157,8 @@ protected: typedef std::pair< unsigned int, unsigned int > SizePair; typedef std::map< SizePair, GlyphMap > SizeGlyphMap; + + osg::ref_ptr _stateset; SizeGlyphMap _sizeGlyphMap; GlyphTextureList _glyphTextureList; StateSetList _stateSetList; diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 4149e045d..b3ef3f09b 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -31,7 +31,7 @@ std::string osgText::findFontFile(const std::string& str) { // try looking in OSGFILEPATH etc first for fonts. std::string filename = osgDB::findDataFile(str); - if (!filename.empty()) return std::string(filename); + if (!filename.empty()) return filename; static osgDB::FilePathList s_FontFilePath; @@ -68,6 +68,11 @@ std::string osgText::findFontFile(const std::string& str) filename = osgDB::findFileInPath(filename,s_FontFilePath); if (!filename.empty()) return filename; } + else + { + filename = osgText::findFontFile(std::string("fonts/")+filename); + if (!filename.empty()) return filename; + } // Not found, return empty string osg::notify(osg::WARN)<<"Warning: font file \""<setRenderingHint(osg::StateSet::TRANSPARENT_BIN); } Font::~Font() diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 043f1bc56..c06929cb3 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -89,6 +89,14 @@ void Text::setFont(Font* font) { if (_font==font) return; + osg::StateSet* previousFontStateSet = _font.valid() ? _font->getStateSet() : 0; + osg::StateSet* newFontStateSet = font ? font->getStateSet() : 0; + + if (getStateSet() == previousFontStateSet) + { + setStateSet( newFontStateSet ); + } + _font = font; computeGlyphRepresentation(); @@ -699,8 +707,6 @@ void Text::computeGlyphRepresentation() } - setStateSet(const_cast((*_textureGlyphQuadMap.begin()).first.get())); - computePositions(); computeColorGradients(); } @@ -1443,6 +1449,7 @@ void Text::drawImplementation(osg::State& state) const glPushAttrib(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_FILL); } + for(TextureGlyphQuadMap::iterator titr=_textureGlyphQuadMap.begin(); titr!=_textureGlyphQuadMap.end(); ++titr) @@ -1505,8 +1512,13 @@ void Text::drawImplementation(osg::State& state) const // Make sure that the main (foreground) text is on top glPolygonOffset(-10, -10); } + glDrawArrays(GL_QUADS,0,transformedCoords.size()); - glPolygonOffset(0,0); + + if(_backdropType != NONE) + { + glPolygonOffset(0,0); + } } }