My app uses the same font everywhere. So, I have a global method to return a reference to a single Font instance:
osg::ref_ptr<osgText::Font> getArialFont() {
  static osg::ref_ptr<osgText::Font> s_font = osgText::readFontFile("fonts/arial.ttf");
  return s_font;
}

When I pass it to Text::setFont(), the Text instance's StateSet gets set to the Font's StateSet. Every Text instance ends up sharing the same StateSet and changes to it end up acting globally. Here's the code from osgText::Text:

void Text::setFont(osg::ref_ptr<Font> font)
{
  if (_font==font) return;
   
  osg::StateSet* previousFontStateSet = _font.valid() ? _font->getStateSet() : DefaultFont::instance()->getStateSet();
  osg::StateSet* newFontStateSet = font.valid() ? font->getStateSet() : DefaultFont::instance()->getStateSet();
   
  if (getStateSet() == previousFontStateSet)
  {
    setStateSet( newFontStateSet );
  }
   
  _font = font;
   
  computeGlyphRepresentation();
}


If I later set some text to be depth sorted and other text to not be depth sorted, then whomever makes the setting last, wins.

I have two questions.
1) Why would you want the Font's StateSet to become the Text's StateSet? Text and Font are very different concepts.
2) Ideally, StateSet would have COW semantics, but it doesn't and it wouldn't be trivial to add. Would it be reasonable to pass a copy of newFontStateSet to Text::setStateSet()?

Cory



_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to