基于osgEarth源码的Sample_osgearth_annotation项目实现汉字显示功能。
向项目中添加文件“MyStringConvert.h”和“MyStringConvert.cpp”。
“MyStringConvert.h”的内容如下:
#pragma once
#include <string>
using namespace std;
void gb2312ToUtf8(const string& src, string& result);
“MyStringConvert.cpp”的内容如下:
#include "MyStringConvert.h"
#include <Windows.h>
#include <stringapiset.h>
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 gb2312ToUnicode(const string& src, wstring& re

本文通过自定义字符串转换函数,实现了osgEarth项目中汉字的正确显示。具体步骤包括添加“MyStringConvert.h”和“MyStringConvert.cpp”两个文件,并在main函数中配置样式以加载中文字体。
最低0.47元/天 解锁文章
299

被折叠的 条评论
为什么被折叠?



