[osg-users] Text Bounding Box Calculation

Daniel Emminizer, Code 5773 dan.emminizer at nrl.navy.mil
Mon May 14 08:02:02 PDT 2018

Hi Robert,

I hope you're not sick of hearing from me yet.  I have uncovered a difference of behavior between 3.4 and 3.6 in osgText::Text's bounding box calculation.  The attached program attempts to demonstrate the difference.

In one place in our application, we are trying to determine the width of a text string in model coordinates.  This works well using getBoundingBox().  The problem we are seeing is if we change the text string, then call getBoundingBox() before drawImplementation() has a chance to run, the bounding box is vastly different than expected.  I believe this is because computePositions() passes in 0 for the osg::State to computeMatrix().

Because of this, it's unclear when we call getBoundingBox if we're getting model coordinates or screen coordinates. (sorry, I'm not sure if that's the correct terminology)

In OSG 3.4, if you run the attached program, you'll get the same value printout before and after change.  In OSG 3.6, you get a value that is vastly larger after.  You can see the relevant code in TextWidthPrinter::handle(), and on the console by pressing 't' at runtime.

This is not a blocker for us because we have access to the osg::State in our code and can multiply against the correct matrix to value we need.  We can #if OSG_VERSION_GREATER_THAN our code.  But this change looks unintentional, so I wanted to pass along this test program that demonstrates the issue.

I hope this is helpful.

 - Dan

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: osgtext.cpp
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180514/bb512d75/attachment.ksh>

More information about the osg-users mailing list