[osg-users] osgText::Text display isse

Helmut Puhr eskay187 at gmx.at
Tue Dec 26 05:36:15 PST 2017


Hi,
  for whatever reason I can not get correct correct 2D text display method working. My code is based on the osghud example, in the background I render a osgEarth map. The text is displayed, but always looks like only the "background" of each character is rendered, please see the attached screenshot.

I am using OSG 3.4.0 release on Ubuntu 17.10 with an NVIDIA GTX 1080 driver 384.90, also using osgEarth 2.8 and the osgEarthQt::Viewer to integrate into Qt5.

The following code should create the HUD:

[code]

void setup ()
{
...
    font_ = osgText::readFontFile(HOME_DATA_DIRECTORY+"fonts/arial.ttf");

    osgViewer::Viewer::Windows windows;
    osg_viewer_->getWindows(windows);

    assert (!windows.empty());

    osg::Camera* hud_camera = createHUDCamera(0,windows[0]->getTraits()->width, 0, windows[0]->getTraits()->height);
    hud_camera->setGraphicsContext(windows[0]);

    osg::ref_ptr<osg::Geode> textGeode = new osg::Geode;
    textGeode->addDrawable (createText(osg::Vec3(150.0f, 300.0f, 0.0f),  "The Cessna monoplane", 10.0f));
    textGeode->addDrawable (createText(osg::Vec3(150.0f, 400.0f, 0.0f),  "Six-seat, low-wing and twin-engined", 15.0f));

    hud_camera->addChild(textGeode);

    root_node_->addChild(hud_camera);
...
}

osg::Camera* OSGViewDataWidget::createHUDCamera (double left, double right, double bottom, double top)
{
    osg::ref_ptr<osg::Camera> camera = new osg::Camera;
    //camera->getOrCreateStateSet()->setGlobalDefaults();
    camera->setReferenceFrame (osg::Transform::ABSOLUTE_RF);
    camera->setClearMask (GL_DEPTH_BUFFER_BIT);
    camera->setRenderOrder (osg::Camera::POST_RENDER);
    camera->setAllowEventFocus (false);
    camera->setProjectionMatrix (osg::Matrix::ortho2D (left, right, bottom, top));
    camera->setViewMatrix(osg::Matrix::identity());
    camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    return camera.release();
}

osgText::Text* OSGViewDataWidget::createText (const osg::Vec3& pos, const std::string& content, float size)
{
    osg::ref_ptr<osgText::Text> text = new osgText::Text;
    //text->setColor(osg::Vec4(0.0f, 1.0f, 1.0f, 1.0f));
    text->setFontResolution (50,50);
    text->setFont (font_.get());
    text->setCharacterSize (size);
    text->setAxisAlignment (osgText::TextBase::XY_PLANE);
    text->setPosition (pos);
    text->setText (content);
    text->setDrawMode (osgText::TextBase::DrawModeMask::FILLEDBOUNDINGBOX | osgText::TextBase::DrawModeMask::TEXT);
    text->setBoundingBoxColor (osg::Vec4(0.0f, 0.0f, 0.2f, 0.25f));
    text->setBoundingBoxMargin (2.0f);
    return text.release();
}
[/code]

I have tried several implementations but can for the life of me can not figure out what the issue is. If I change the font, the displayed white boxes change as well, so at least something happens ...

Can someone point me in the right direction? Any hep would be appreciated.


Thank you!

Cheers,
Helmut

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




Attachments: 
http://forum.openscenegraph.org//files/osgtext_issue_172.png




More information about the osg-users mailing list