查看: 6935|回复: 9

osgEarth 中的 LabelNode 是不是不能显示中文

[复制链接]

该用户从未签到

发表于 2012-6-18 17:25:46 | 显示全部楼层 |阅读模式
如题

不知大家有么有用过,有没有使用成功的办法,谢谢

该用户从未签到

发表于 2012-6-18 21:18:44 | 显示全部楼层

该用户从未签到

发表于 2012-7-26 13:07:51 | 显示全部楼层
论坛上的解决方案,检验可行,个人认为没必要去改动源码:
wstring  mss = _T("中国");
std::string ss = osgDB::convertUTF16toUTF8(mss);

// set up a style to use for labels:
osgEarth::Annotation::Symbology::Style labelStyle;
labelStyle.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_UTF8;
labelStyle.getOrCreate<TextSymbol>()->font() = std::string("fonts/SimHei.ttf");

该用户从未签到

发表于 2012-10-15 15:57:59 | 显示全部楼层
microicefish 发表于 2012-7-26 13:07
论坛上的解决方案,检验可行,个人认为没必要去改动源码:
wstring  mss = _T("中国");
std::string ss = os ...

hi,
我使用这个方法的时候,为什么提示“error LNK2019:unresolved external symbol "_declspec(dllimport) calls std::basic<char, struct std::char _traits<char>,class stad::allocator<char> _cdecl osgDB::covertUTF16toUTF8..."”

好像是连接错误,但是我已经添加了osgdb.lib

为什么呢?

该用户从未签到

发表于 2012-10-15 16:18:00 | 显示全部楼层
检查 lib  头文件引用

该用户从未签到

发表于 2012-10-15 19:48:49 | 显示全部楼层
basten-1982 发表于 2012-10-15 15:57
hi,
我使用这个方法的时候,为什么提示“error LNK2019:unresolved external symbol "_declspec(dllimp ...

这个问题我也遇到过,当时解决的办法是把要用的几个函数从osgDB里抽出来自己写了一个.h文件,这个错误估计是osg编译的问题,和版本有关系

该用户从未签到

发表于 2013-1-29 16:26:24 | 显示全部楼层
我用这个方法是提示error C2039: “convertUTF16toUTF8”: 不是“osgDB”的成员 难道是版本不一样?

该用户从未签到

发表于 2013-2-23 00:18:08 | 显示全部楼层
改动依赖库的源代码是绝对错误的行为。我这里有不改依赖库源代码的解决方案。

void unicodeToUTF8(const wstring &src, string& result)
{
    int n = WideCharToMultiByte( CP_UTF8, 0, src.c_str(), -1, 0, 0, 0, 0 );
    result.resize(n);
    ::WideCharToMultiByte( CP_UTF8, 0, src.c_str(), -1, (char*)result.c_str(), result.length(), 0, 0 );
}

void unicodeToGB2312(const wstring& wstr , string& result)
{
    int n = WideCharToMultiByte( CP_ACP, 0, wstr.c_str(), -1, 0, 0, 0, 0 );
    result.resize(n);
    ::WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, (char*)result.c_str(), n, 0, 0 );
}

void utf8ToUnicode(const string& src, wstring& result)
{
    int n = MultiByteToWideChar( CP_UTF8, 0, src.c_str(), -1, NULL, 0 );
    result.resize(n);
    ::MultiByteToWideChar( CP_UTF8, 0, src.c_str(), -1, (LPWSTR)result.c_str(), result.length());
}

void gb2312ToUnicode(const string& src, wstring& result)
{
    int n = MultiByteToWideChar( CP_ACP, 0, src.c_str(), -1, NULL, 0 );
    result.resize(n);
    ::MultiByteToWideChar( CP_ACP, 0, src.c_str(), -1, (LPWSTR)result.c_str(), result.length());
}

void gb2312ToUtf8(const string& src, string& result)
{
    wstring strWideChar;
    gb2312ToUnicode(src, strWideChar);
    unicodeToUTF8(strWideChar, result);
}

char wsrc[512];
sprintf(wsrc, "飞机型号:\n经    度:%.2f\n纬    度:%.2f\n高    度:%.2f\n",  lla.x(), lla.y(), lla.z());
string strUtf8;
gb2312ToUtf8(string(wsrc), strUtf8);
flyCoords->setEncoding(osgText::String::ENCODING_UTF8);
flyCoords->setText(strUtf8.c_str());

该用户从未签到

发表于 2013-9-28 07:40:59 | 显示全部楼层
microicefish 发表于 2012-7-26 13:07
论坛上的解决方案,检验可行,个人认为没必要去改动源码:
wstring  mss = _T("中国");
std::string ss = os ...

我也测试了,在unicode下运行能够通过,但是显示的还是乱码啊,
同样我在多字符集下修改了,还是乱码
wstring  mss = L"中国";//
std::string ss = osgDB::convertUTF16toUTF8(mss);

// set up a style to use for labels:
osgEarth::Annotation::Symbology::Style labelStyle;
labelStyle.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_UTF8;
labelStyle.getOrCreate<TextSymbol>()->font() = std::string("fonts/SimHei.ttf");

该用户从未签到

发表于 2013-9-28 07:58:30 | 显示全部楼层
好勤奋O
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表