ImGui: 如何卸载从内存加载的字体 (AddFontFromMemoryTTF) - 示例代码
在 ImGui 中,卸载字体可以通过 io.Fonts->Clear() 来实现。以下是一个示例代码,演示如何加载和卸载字体:
// 加载字体
static const unsigned char font_data[] = { /* 字体数据 */ };
static const int font_size = sizeof(font_data);
ImFont* font = ImGui::GetIO().Fonts->AddFontFromMemoryTTF((void*)font_data, font_size, 16.0f);
// 使用字体
ImGui::PushFont(font);
ImGui::Text('Hello, world!');
ImGui::PopFont();
// 卸载字体
ImGui::GetIO().Fonts->Clear();
在这个示例中,我们首先使用 io.Fonts->AddFontFromMemoryTTF 从内存中加载了一个字体,然后使用 ImGui::PushFont 将该字体设置为当前使用的字体,最后在使用完毕后使用 ImGui::GetIO().Fonts->Clear() 卸载该字体。
原文地址: https://www.cveoy.top/t/topic/nw5O 著作权归作者所有。请勿转载和采集!