osg、osgearth支持中文

字体库支持 freetype

要使osg、osgearth支持中文,必须要有 freetype,所以在编译它们前,先编译好 freetype。并且在编译osg时,使用freetype库。

环境变量

osg中使用的默认字体是不支持中文的,所以需要设置默认字体。这个可以通过环境变量来修改。

    export OSGEARTH_DEFAULT_FONT=simsun.ttc

以上是设置默认字体为仿宋

代码

在代码中,使用字符编码为: utf8

osgEarth::Util::Controls::LabelControl* pLabel =
            new osgEarth::Util::Controls::LabelControl();
pLabel->setEncoding(osgText::String::ENCODING_UTF8);
pLabel->setText(tr("Coordinate:").toUtf8().data());
osgEarth::Style pm;
pm.getOrCreate<osgEarth::IconSymbol>()->declutter() = true; 
pm.getOrCreate<osgEarth::TextSymbol>()->halo() = osgEarth::Color("#5f5f5f"); 
pm.getOrCreate<osgEarth::TextSymbol>()->encoding() = 
            osgEarth::TextSymbol::ENCODING_UTF8;
labelGroup->addChild(new osgEarth::Annotation::PlaceNode(m_MapNode, osgEarth::GeoPoint(geoSRS, start.x(), start.y()), tr("Start").toUtf8().data(), pm));
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值