Loading Custom Font with ImGui
TrevorCash opened this issue · 2 comments
Hi @mosra,
I am loading a custom font with imgui:
ImGui::CreateContext();
ImFontConfig fontConfig;
fontConfig.FontDataOwnedByAtlas = false;
size_t fileSize;
auto data = ControlSingleton::GetInstance()->zipResourceManager->AccessResource("Fonts/OpenSans-Bold.ttf", fileSize);
ImGui::GetIO().Fonts->Clear();
pAppFont = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(data, fileSize, 16.0, &fontConfig);
ImGui::GetIO().Fonts->Build();
_imgui = ImGuiIntegration::Context(Vector2{ windowSize() } / dpiScaling(),
windowSize(), framebufferSize());
This is in a GLFW application.
I am getting the following texture error:

The data is preset for the font and is persistent for the lifetime of the application.
Are there extra operations needed with texturing?
Thanks,
Trevor
Hey! :)
Are you following the snippet in the docs? In particular, it seems to me that you're creating ImGuiIntegration::Context without telling it to take over the existing ImGui context, which then causes it to create a second ImGui context and then ... it likely blows up due to that mismatch. It seems. In other words, can you try this instead?
// v-------- this ------------
_imgui = ImGuiIntegration::Context(*ImGui::GetCurrentContext(),
Vector2{ windowSize() } / dpiScaling(), windowSize(), framebufferSize());By the way, not sure which commit are you on, but in mosra/magnum-integration@1117d6f I made a change that it no longer stores a pointer to a texture (which causes this kind of nasty crashes) but an OpenGL texture object ID instead. With that change, in case such context/texture mismatch somehow happens again, either due to fonts or any other reason, it will behave robustly and not blow up like that.
Hey :) , I think I am using a new enough commit with the texture changes. Fixing the context bug is working great - thanks.