osgText中文字体的处理
(2012-10-30 15:25:38)
标签:
osgtext中文字体显示
|
分类:
osg
|
宽字节转换.
inline wchar_t* AnsiToUnicode( const char* szStr
)
{
int nLen = MultiByteToWideChar( CP_ACP,
MB_PRECOMPOSED, szStr, -1, NULL, 0 );
if (nLen ==
0)
{ return
NULL;
}
wchar_t* pResult = new
wchar_t[nLen];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
szStr, -1, pResult, nLen );
return pResult;
}
//osg汉字处理.
osg::ref_ptr<osg::Node>
CWayPoint::createText()
{
m_objectBillboard = new osg::Billboard;
m_mtxBillboard->addChild(m_objectBillboard);
osg::ref_ptr<osgText::Font> font =
osgText::readFontFile(
"fonts/simhei.ttf" );//读取中文字体
osg::Vec4
color(0.0f,0.0f,1.0f,1.0f);
osg::ref_ptr<osgText::Text> text =
new osgText::Text();
text->setFont(font);
text->setColor(color);
text->setCharacterSize(0.18f);
text->setAxisAlignment(osgText::TextBase::XZ_PLANE);
text->setText(AnsiToUnicode(m_objectName));//字体转换;
text->setDrawMode(osgText::Text::BOUNDINGBOX
| osgText::Text::TEXT);
m_objectBillboard->addDrawable(text.get());
m_objectBillboard->setMode(osg::Billboard::POINT_ROT_EYE);
m_objectBillboard->setPosition(0,osg::Vec3d(0.0f,0.0f,0.5f));
m_mtxBillboard->addChild(createLine());
m_mtxBillboard->getOrCreateStateSet()->addUniform(new
osg::Uniform("TextureNum", -1));
return
m_mtxBillboard;
}
喜欢
0
赠金笔
加载中,请稍候......