找回密码
 立即注册
首页 业界区 安全 SDL2下ImGUI的中文字体显示问题

SDL2下ImGUI的中文字体显示问题

醋辛 7 天前
头文件
  1. #include "imgui/imgui.h"
  2. #include "imgui/imgui_sdl.h"
  3. #include "imgui/imgui_impl_sdl.h"
复制代码
在SDL渲染器创建完毕之后
  1. ImGui::CreateContext();
  2. ImGuiIO& io = ImGui::GetIO();
  3. ImFont* font = io.Fonts->AddFontFromFileTTF(
  4.         "./assets/fonts/simhei.ttf",  // 微软雅黑或思源黑体路径
  5.         18.0f,                          // 字号
  6.         nullptr,                        // 使用默认配置
  7.         io.Fonts->GetGlyphRangesChineseFull() // 指定中文字符范围
  8. );
  9. // io.Fonts->TexDesiredWidth = 4096; // 默认1024可能不够
  10. io.Fonts->Build();
  11. ImGuiSDL::Initialize(renderer, windowWidth, windowHeight);
复制代码
循环绘制
  1. ImGui::NewFrame();
  2. if (ImGui::Begin(u8"产生敌人")) {
  3.         ImGui::Text(u8"这里是产生新敌人的地方");
  4. }
  5. ImGui::End();
  6. ImGui::Render();
  7. ImGuiSDL::Render(ImGui::GetDrawData());
复制代码
垃圾回收
  1. ImGuiSDL::Deinitialize();
  2. ImGui::DestroyContext();
复制代码
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册