[osg-users] Disappearing text

Ronny Hatteland ronnyhatteland at gmail.com
Sun Apr 17 09:58:40 PDT 2016


Hi,

By coincidence I made some progress to an issue that has been bugging me for two years, where the osgText disappears in a certain case. I am using VBO hardware instancing for another object, and when only the text and the VBO hardware instanced objects are visible (using a Switch node), the text disappears.

Previously, I though it was related to the bounding box of the VBO instances, as the text would appear again if other objects were shown at the same time. However, today I noticed that when the text was not updated on cursor move, the original text that was set on the creation of the osgText::Text object would be visible as expected.

The text is updated using txtObject->SetText(text) with the cursor position on a grid on the xz plane, with a text looking like this "(%d, %d)". Below is the code for the initialization of the text objects:


Code:

txtSelectedCell = new osgText::Text;
txtSelectedCell->setDataVariance(Object::DYNAMIC);
txtSelectedCell->setFont(consolasBold);
txtSelectedCell->setFontResolution(128, 128);
txtSelectedCell->setCharacterSizeMode(osgText::TextBase::OBJECT_COORDS);
txtSelectedCell->setLineSpacing(0.10f);
txtSelectedCell->setPosition(osg::Vec3(0.0, /*-0.001*/0.0, 0.0));
txtSelectedCell->setCharacterSize(0.0015f);
txtSelectedCell->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
txtSelectedCell->setBackdropType(osgText::Text::OUTLINE);
txtSelectedCell->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
txtSelectedCell->setBackdropOffset(0.10f, 0.10f);
txtSelectedCell->setAxisAlignment(osgText::Text::XZ_PLANE);
txtSelectedCell->setAlignment(osgText::Text::CENTER_CENTER);
txtSelectedCell->setText("(X,Y)");

ref_ptr<Geode> infoCellText = new osg::Geode;
infoCellText->setDataVariance(Object::DYNAMIC);
infoCellText->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
infoCellText->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
infoCellText->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
infoCellText->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
text_program = LoadShaderProgram("textMaterial.vert", "textMaterial.frag");;
infoCellText->getOrCreateStateSet()->setAttributeAndModes(text_program.get(), osg::StateAttribute::ON);
osgUtil::GLObjectsVisitor glov(osgUtil::GLObjectsVisitor::TRAVERSE_ALL_CHILDREN | osgUtil::GLObjectsVisitor::SWITCH_OFF_DISPLAY_LISTS | osgUtil::GLObjectsVisitor::SWITCH_ON_VERTEX_BUFFER_OBJECTS);
ref_ptr<osg::State> state = new osg::State(); glov.setState(state);
infoCellText.get()->accept(glov);
infoCellText->setCullingActive(false);
infoCellText->addDrawable(txtSelectedCell.get());
ref_ptr<MatrixTransform> mtSelectedCell->addChild(infoCellText); // Updated on mouse move




Exploring this further, I created a new text object each time position on the grid was updated, that I added to the infoCellText geode. This would work only if I did not remove the original txtSelectedCell child. However, it would not work if txtSelectedCell->SetText was initialized to "" instead of "(X,Y)". If the txtSelectedCell text was changed with setText at the same time as a new osgText was added to the infoCellText geode, the text would not show.

I suspect this has something to do with the bounding box of the text, however, I am not entirely sure if it is related to the osgText::Text object or the Geode with the text as a child. I tried to call computeBound() on txtSelectedCell as well as infoCellText after updating the text with setText(), but without any luck. In many cases when the text is not displayed I get weird artifacts with planes cutting through the view. Any suggestions would be extremely appreciated.

Thank you!

Cheers,
Ronny

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66845#66845








More information about the osg-users mailing list