|
//创建文字
osg::ref_ptr<osg::Geode> cOSG::createText(double x,double y,double z,CString strvalue)
{
setlocale(LC_ALL,".936");
osg::ref_ptr<osgText::Text> text = new osgText::Text;
osg::ref_ptr<osgText::Font> font = new osgText::Font();
//读取字体
font = osgText::readFontFile("simhei.ttf");
// 设置字体文件
text->setFont(font.get());
CString st;
st="fff中华";
char *p =(LPSTR)(LPCSTR)strvalue;
int resize=mbstowcs(NULL,p,0);
wchar_t* wtext=new wchar_t[resize+1];
mbstowcs(wtext,p,resize+1);
//text1->setText(wtext);
//std::string str(st);
//osgText::String value(str);
// 设置文字信息
text->setText(wtext);//L(st));//"中国北京");
// 设置字体大小wtext);//L
text->setCharacterSize(10);
//
//设置字体颜色
text->setColor( osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f) );
text->setAutoRotateToScreen(true);
// 设置显示的位置
osg::Vec3f position ;
position.set(x,y,z);//4568.5312,-8387.43457,30);//
text->setPosition( position );
text->setAxisAlignment(osgText::TextBase::XZ_PLANE); //osgText::Text::SCREEN);//
//添加到叶节点中
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
/* osg::ref_ptr<osg::Billboard> BBD = new osg::Billboard;
BBD->setName(strvalue.GetBuffer(0));
BBD->setMode(osg::Billboard:OINT_ROT_EYE);
BBD->addDrawable(text.get());*/
/*delete p;
delete wtext;
return BBD.get() ;*/
geode->addDrawable(text.get());
delete p;
delete wtext;
return geode.get() ;
}
现在的问题是文字不能指向视点 如何能解决?" |
|