[osg-users] Disappearing text

Robert Osfield robert.osfield at gmail.com
Mon Apr 18 00:27:40 PDT 2016


Hi Ronny,

Without seeing the artificats first hand is not possible to know what is
going on.  The best I can suggest is that you look at the near/far planes
of the scene, could it be that the near/far planes are clipping the text?

Also look at the possibility of state leaking into the text for some
reason. Do you have custom OpenGL code?

Finally, which OSG version are you using?  The latest OSG version will
likely have the most bug fixes so there is small chance that this might
address issues.

Robert.

On 17 April 2016 at 17:58, Ronny Hatteland <ronnyhatteland at gmail.com> wrote:

> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160418/bc07a179/attachment-0003.htm>


More information about the osg-users mailing list