[osg-users] osgText::Text display issue (only white boxes rendered)
Julien Valentin
julienvalentin51 at gmail.com
Thu Dec 28 14:34:48 PST 2017
Hi,
I think you should make a simple example to track where the bug is:
Personnaly I experienced a lot of conflicts between osg and qt renderer especially since I use qml for gui and embed osg rendering in a QQuickViewport (both qt and osg changed GL state leading to conflicts)
Try to reproduce the bug without Qt, if the problem persists, it's an osg bug. Only then, you'll can give us a simple cpp example (in attachment) to diagnose easily the issue.
Cheers
eskay187 wrote:
> 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();
> }
>
>
>
>
> 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 help would be appreciated.
>
>
> Thank you!
>
> Cheers,
> Helmut
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72649#72649
More information about the osg-users
mailing list