Change osgText so that the Text drawable now can have its own StateSet

that users can assign to it without it being overriden.  If none is
assigned externally it now uses a StateSet associated wit the Font assigned
to the Text.
This commit is contained in:
Robert Osfield
2006-07-04 13:56:29 +00:00
parent e8a3444b88
commit 3ad5140942
3 changed files with 33 additions and 4 deletions

View File

@@ -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<osg::StateSet> _stateset;
SizeGlyphMap _sizeGlyphMap;
GlyphTextureList _glyphTextureList;
StateSetList _stateSetList;

View File

@@ -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 \""<<str<<"\" not found."<<std::endl;
@@ -76,6 +81,8 @@ std::string osgText::findFontFile(const std::string& str)
osgText::Font* osgText::readFontFile(const std::string& filename)
{
if (filename=="") return 0;
std::string foundFile = findFontFile(filename);
if (foundFile.empty()) return 0;
@@ -132,6 +139,9 @@ Font::Font(FontImplementation* implementation):
{
setImplementation(implementation);
_texEnv = new osg::TexEnv(osg::TexEnv::BLEND);
_stateset = new osg::StateSet;
_stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
Font::~Font()

View File

@@ -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<osg::StateSet*>((*_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);
}
}
}