[osg-users] Text size and overlapping on osg sphere.

Inna Reddy osgforum at tevs.eu
Thu Nov 10 05:53:03 PST 2016


Hi all,

I have made osg sphere and drawign text on it. Currently , my code palces the text in some places on the sphere.I am facing three issues. 

1. But when I have  more numbers of texts . few of them are overlapping each other. Is ther any way to avoid this from osg or its pure mathematics. 

2. Text also overlapping with the behind the text. Lets say, when the text1 is on the backside of the sphere , it overlapps with the text which is on the front surface of the sphere. Is it possible to set not to happen like that. 

3. I am using character size text->setCharacterSize(500000);. Which is very big number, If I use smaller than this. its really bad. What's casuing this issue? 

currently, this is the code I am using to draw the text on the sphere. 
osgText::Text* createText(osg::EllipsoidModel* ellipsoid, double latitude, double longitude, double height, const std::string& str)
{
	double X, Y, Z;
	ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(latitude), osg::DegreesToRadians(longitude), height, X, Y, Z);


	osgText::Text* text = new osgText::FadeText;

	osg::Vec3 normal = ellipsoid->computeLocalUpVector(X, Y, Z);
	text->setCullCallback(new osg::ClusterCullingCallback(osg::Vec3(X, Y, Z), normal, 0.0));

	text->setText(str);
	osg::ref_ptr<osgText::Font> font = osgText::readFontFile("fonts/CalibriLI.ttf");
	text->setFont(font.get());
	text->setColor(osg::Vec4(1.0f, 1.0f, 1.0, 1.0f));
	text->setPosition(osg::Vec3(X, Y, Z));
	text->setCharacterSize(500000);
	text->setDrawMode(osgText::Text::TEXT /*| osgText::Text::BOUNDINGBOX*/);
	text->setAxisAlignment(osgText::Text::SCREEN);
	//text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT);
	text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
	text->setAutoRotateToScreen(true);
	return text;
}

//**********************************************************
osg::Node* createTextOnEllipsoid(osg::EllipsoidModel* ellipsoid)
{
	osg::Group* group = new osg::Group;

	group->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

	osg::Geode* geode = new osg::Geode;
	group->addChild(geode);

	std::vector<std::string> textList;
	textList.push_back("England");
textList.push_back("Netherlands");
	textList.push_back("Russia");
	textList.push_back("Japan");
	textList.push_back("This is not country");

	unsigned int numLat = 10;
	unsigned int numLong = 10;
	double latitude = 0.0;
	double longitude = -100.0;
	double deltaLatitude = 1.0f;
	double deltaLongitude = 1.0f;
	 int t = 0;
	for ( int i = 0; i < textList.size(); ++i, longitude += rand() % 1000){
		std::cout << " i value :: \n " << i << "Lat::" << latitude;
		for ( int k = 0; k < numLong; ++k, t++, latitude += rand() % 100){
			std::cout << " K value :: \n " << k << "latitude"<< latitude;
			geode->addDrawable(createText(ellipsoid, latitude, longitude, 0, textList[t % textList.size()]));
		}
	}
	
	return group;	
}


... 

Thank you!

Cheers,
Inna

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








More information about the osg-users mailing list