头文件
#include "imgui/imgui.h"
#include "imgui/imgui_sdl.h"
#include "imgui/imgui_impl_sdl.h"
在SDL渲染器创建完毕之后
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
ImFont* font = io.Fonts->AddFontFromFileTTF(
"./assets/fonts/simhei.ttf", // 微软雅黑或思源黑体路径
18.0f, // 字号
nullptr, // 使用默认配置
io.Fonts->GetGlyphRangesChineseFull() // 指定中文字符范围
);
// io.Fonts->TexDesiredWidth = 4096; // 默认1024可能不够
io.Fonts->Build();
ImGuiSDL::Initialize(renderer, windowWidth, windowHeight);
循环绘制
ImGui::NewFrame();
if (ImGui::Begin(u8"产生敌人")) {
ImGui::Text(u8"这里是产生新敌人的地方");
}
ImGui::End();
ImGui::Render();
ImGuiSDL::Render(ImGui::GetDrawData());
垃圾回收
ImGuiSDL::Deinitialize();
ImGui::DestroyContext();