[osg-users] osgText::Text::getBound()

Alan Purvis alanpurvis at eircom.net
Wed Sep 12 09:17:22 PDT 2007


Hi,

I need to compute the bounds of an osgText::Text object in some code  
of mine, with the caveat that I need these bounds before I attach it  
to the scenegraph.

				_geode = new osg::Geode();
				_text = new osgText::Text();

				_text->setPosition(POS);
				_text->setLayout(osgText::Text::LEFT_TO_RIGHT);
				_text->setAlignment(ALIGN);
				_text->setText(STR);
				_text->setColor(osg::Vec4(1, 1, 1, 1));

				addChild(_geode.get());
				_geode->addDrawable(_text.get());

				----------------------------

				_text->dirtyBound(); // this has no effect
				osg::BoundingBox bounds = _text->computeBound(); // getBound  
returns the same results!
				return bounds;

				----------------------------

				osg::BoundingBox textbounds = text->bounds();
				const float bottom = textbounds.yMin();
				const float top = textbounds.yMax();
				const float left = textbounds.xMin();
				const float right = textbounds.xMax();
				const float buttonsize = 75.0;
				const float textoffset[2] = {-5.0, -55.0};
				
				std::cout << "[" << left << ", " << bottom << "] -> [" << right  
<< ", " << top << "]\n";

Running this code however does not return the same bounds every time...

	[Session started at 2007-09-12 16:27:25 +0100.]
	[500, 1.50324e+11] -> [500, 1.50324e+11]

	[Session started at 2007-09-12 16:29:54 +0100.]
	[500, 475] -> [820, 557]

	[Session started at 2007-09-12 16:30:28 +0100.]
	[500, 475] -> [820, 557]

	[Session started at 2007-09-12 16:31:25 +0100.]
	[inf, 3.40282e+38] -> [-inf, -3.40282e+38]

	[Session started at 2007-09-12 16:32:14 +0100.]
	[500, 475] -> [820, 557]

	[Session started at 2007-09-12 16:33:08 +0100.]
	[3.40282e+38, 3.40282e+38] -> [-3.40282e+38, -3.40282e+38]

	[Session started at 2007-09-12 16:33:59 +0100.]
	[500, 475] -> [820, 557]
	
	[Session started at 2007-09-12 16:34:26 +0100.]
	[3.40282e+38, 3.40282e+38] -> [-3.40282e+38, -3.40282e+38]

	[Session started at 2007-09-12 16:35:02 +0100.]
	[500, 475] -> [820, 557]

	[Session started at 2007-09-12 16:38:12 +0100.]
	[3.40282e+38, 3.40282e+38] -> [-3.40282e+38, -3.40282e+38]

3.40282e+38 is the value of FLT_MAX unless I'm mistaken, these appear  
to be the values of a freshly initialised bounding box (BB Ctor sets  
these values by default). Does the fact I'm computing these bounds  
before I'm attaching the node to the SG have any importance here? The  
"osghud" example program doesn't appear to attach its text objects to  
any kind of viewer before it extracts the bounds, and it appears to  
get correct values.

Is there some function I need to manually call to force the text  
object to construct its internals before I grab the bounds? Is the  
creation of the text objects internal data happening in another  
thread or somehow asynchronously with my calls to getBound()/ 
computeBound()?

I'm using osg 2.0, the standard release, if it helps to know.

Thanks a lot,
Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20070912/15a10916/attachment-0002.htm>


More information about the osg-users mailing list