Re: [osg-users] StateSet and Text, state sets may be shared inadvertently
On 05/01/12 18:25, Robert Osfield wrote: Hi Juan, osgText::Text is a special case in that the way the text is rendered is using textures and to for best performance and memory usage you need to share these textures, and also share the rest of the text state as well. OK, I see, I didn't think of the textures. If you want to decorate the Text with your custom StateSet than it's best to place it on a Geode above the Text object. Does that mean that if I use a StateSet created by myself for each text style and then do setStateSet in each text object, the textures will be duplicated for each StateSet? I'm asking because currently I have more drawables in the geode that holds the text and I prefer not having to change that. Thanks, Juan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] StateSet and Text, state sets may be shared inadvertently
Hi Juan, osgText::Text is a special case in that the way the text is rendered is using textures and to for best performance and memory usage you need to share these textures, and also share the rest of the text state as well. If you want to decorate the Text with your custom StateSet than it's best to place it on a Geode above the Text object. Robert. On 4 January 2012 17:31, Juan Hernando jherna...@fi.upm.es wrote: 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. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] StateSet and Text, state sets may be shared inadvertently
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 osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org