char * DO_Text::localeToUTF8(char * src)
{
char *buf = NULL;
if (buf) {
free(buf);
buf = NULL;
}
wchar_t *unicode_buf;
int nRetLen = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
unicode_buf = (wchar_t*)malloc((nRetLen + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, src, -1, unicode_buf, nRetLen);
nRetLen = WideCharToMultiByte(CP_UTF8, 0, unicode_buf, -1, NULL, 0, NULL, NULL);
buf = (char*)malloc(nRetLen + 1);
WideCharToMultiByte(CP_UTF8, 0, unicode_buf, -1, buf, nRetLen, NULL, NULL);
free(unicode_buf);
return buf;
}
然后
TTF_RenderUTF8_Blended(font, localeToUTF8("hello word 世界你好!"), fg);
方法来自博客
{
char *buf = NULL;
if (buf) {
free(buf);
buf = NULL;
}
wchar_t *unicode_buf;
int nRetLen = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
unicode_buf = (wchar_t*)malloc((nRetLen + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, src, -1, unicode_buf, nRetLen);
nRetLen = WideCharToMultiByte(CP_UTF8, 0, unicode_buf, -1, NULL, 0, NULL, NULL);
buf = (char*)malloc(nRetLen + 1);
WideCharToMultiByte(CP_UTF8, 0, unicode_buf, -1, buf, nRetLen, NULL, NULL);
free(unicode_buf);
return buf;
}
然后
TTF_RenderUTF8_Blended(font, localeToUTF8("hello word 世界你好!"), fg);
方法来自博客