首先添加字体
ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\simsun.ttc", 16.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
方法一:直接显示中文
ImGui::Text(u8"测试");
方法二:可用作变量传值显示中文
string str = "测试";
ImGui::Text(TBS(str).c_str());
std::string TBS(std::string & str)
{
typedef std::codecvt_byname<wchar_t, char, std::mbstate_t>F;
static std::wstring_convert<F>strC(new F("Chinese"));
static std::wstring_convert<std::codecvt_utf8<wchar_t>> strCnv;
return strCnv.to_bytes(strC.from_bytes(str));
}