mosra / magnum-integration

Integration libraries for the Magnum C++11 graphics engine
https://magnum.graphics/
Other
99 stars 44 forks source link

ImGui fonts not working #51

Closed melix99 closed 5 years ago

melix99 commented 5 years ago

I'm having problems to use custom fonts with ImGui. Normally in ImGui doing AddFontFromFileTTF(path) will use automatically that font as the default. But when I try to use it with magnum it does nothing: the default imgui font remains. I also tried to check if the font is NULL but it wasn't. The strange fact is that when I try to use PushFont(font)/PopFont() it give me assertion error here. Now IDK if maybe there is something that I am missing to use fonts or it is a bug.

ImGui version: docking, latest commit https://github.com/ocornut/imgui/commit/9f35ba8546b075dfb5d148be4e468ef8c0f5a41c (I even tried the 1.71 release) ImGuiIntegration: latest commit https://github.com/mosra/magnum-integration/commit/b157344afcbff29d20b36a80a999c28329e7bf8c

I'm using Sdl2Application if that's relevant.

mosra commented 5 years ago

Hi,

the desired usage was calling AddFontFromFileTTF() before instantiating ImGuiIntegration::Context, so it then picks it up as a default font. In order to correctly handle HiDPI rendering, it needs to do some additional setup on the fonts. so if you did that after, there already was a default font and it didn't expect any further changes.

In d774aebfc7f8061bbc1331d21b2a323be1ad477f I made it possible to make font changes after ImGuiIntegration::Context is instantiated, but in order to make it pick up the changes correctly and upload an updated glyph cache, you need to explicitly call relayout() after. The docs about font handling were all over the place, so I consolidated them to a single section in 8408dd2b6c50e5d2ea0317d6adc84e643ab32713, hopefully making everything clearer. Will upload the updated docs later today, I have some other pending edits to make.

Let me know if the above works for you. In case you run into further issues, the ports branch of magnum-examples has a modified imgui example where it loads a font that looks better on HiDPI screens, so you can compare to the code from there.

melix99 commented 5 years ago

Thank you! I looked at the example to fix it. The problem that I occurred is that I didn't know I could create an ImGui::Context manually and then pass it to ImGuiIntegration, so this has confused me on how I could add the font in between the two.