Dear all,
Trying to use different StateSet with different osgText::Text objects it happens that all text objects transparently may share the same StateSet depending on how the state sets are created. Image that we have two text objects t1 and t2, then the following calling sequences behave as follows:

Case 1
  t1->getOrCreateStateSet()
  // t2 with the default empty state set
t1 will have a new StateSet and t2 will inherit it from its parent.

Case 2
  t1->getOrCreateStateSet()
  t2->getOrCreateStateSet()
Both texts will use the same state

Case 3
  t1->setStateSet(a_state)
  t2->getOrCreateStateSet()
Each object will have its own state.

Case 4
  t1->getOrCreateStateSet()
  t2->setStateSet(a_state)
Each object will have its own state.

Case 5
  t1 // created first no stateset assigned
  t2->getOrCreateStateSet()
Both texts will use the same state

While it may make sense, it seems a bit weird to me.
If this is the expected behaviour I couldn't find where does it say so in the reference. Is it actually supposed to work like that and what is the reason behind it?

Thanks and regards,
Juan

PS I attach a simple program in case someone wants to verify my statements.
#include <osgViewer/Viewer>
#include <osgText/Text>
#include <osgText/Font>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osg/Depth>
#include <osg/Material>
#include <iostream>

int main()
{
    osgViewer::Viewer viewer;

    osg::Geode *geode = new osg::Geode();

    geode->addDrawable
        (new osg::ShapeDrawable(new osg::Box(osg::Vec3(0, 0, 0), 20, 20, 20)));

    osgText::Text *text1 = new osgText::Text();
    text1->setText("label1");
    text1->setPosition(osg::Vec3(10, 10, 10));
    text1->setAxisAlignment(osgText::Text::SCREEN);
    geode->addDrawable(text1);

    // Uncommenting this line and commeting the other two below will cause
    // both labels to share the same text.
    //state = text1->getOrCreateStateSet();
    osg::StateSet *state = new osg::StateSet();
    //text1->setStateSet(state);
    //state->setAttributeAndModes
    //    (new osg::Depth(osg::Depth::ALWAYS, 0, 1, false));        
    osg::Material *material = new osg::Material();
    //material->setDiffuse(osg::Material::FRONT, osg::Vec4(1, 0, 0, 1));
    //state->setAttributeAndModes(material);

    osgText::Text *text2 = new osgText::Text();
    text2->setText("label2");
    text2->setPosition(osg::Vec3(-10, -10, -10));
    text2->setAxisAlignment(osgText::Text::SCREEN);
    geode->addDrawable(text2);
    material = new osg::Material();
    material->setDiffuse(osg::Material::FRONT, osg::Vec4(0, 0, 1, 1));
    state = text2->getOrCreateStateSet();
    state->setAttributeAndModes(material);

    viewer.setSceneData(geode);
    viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to