|
发表于 2014-3-25 17:20:28
|
显示全部楼层
请参考如下代码:
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
float characterSize=800;//radius*0.2f;
float characterDepth=characterSize*0.2f;
setlocale(LC_ALL,".936");
//osg::Vec3 pos(center.x(),center.y(),center.z());
osgText::Text3D* text1 = new osgText::Text3D;
text1->setFont("fonts/simhei.ttf");
text1->setCharacterSize(characterSize);
text1->setCharacterDepth(characterDepth);
//text1->setPosition(pos); 在显示3D文字,程序运行第一次时设置位置是正确的,第二次后所有位置都在坐标系原点,造成显示重叠,显示位置不对
text1->setDrawMode(osgText::Text3D::TEXT | osgText::Text3D::BOUNDINGBOX);
text1->setAxisAlignment(osgText::Text3D::XZ_PLANE);
//text1->setRenderMode(osgText::Text3D:ER_GLYPH);
int resize=mbstowcs(NULL,txt,0);
wchar_t* wtext=new wchar_t[resize+1];
mbstowcs(wtext,txt,resize+1);
text1->setText(wtext);
geode->addDrawable(text1);
osg::ref_ptr<osg::Group> rootNode = new osg::Group;
rootNode->addChild(geode);
delete wtext;
osg::Material* front = new osg::Material;
front->setAlpha(osg::Material::FRONT_AND_BACK,1);
front->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(0.2,0.2,0.2,1.0));
front->setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0,0.0,1.0,1.0));
rootNode->getOrCreateStateSet()->setAttributeAndModes(front);
return rootNode.release();
另外将项目的字符集设为多字节字符集 |
|