Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui fonts not working #51

Closed
Melix19 opened this issue Jul 21, 2019 · 2 comments

Comments

@Melix19
Copy link

commented Jul 21, 2019

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 ocornut/imgui@9f35ba8 (I even tried the 1.71 release)
ImGuiIntegration: latest commit b157344

I'm using Sdl2Application if that's relevant.

@mosra mosra added this to the 2019.0b milestone Jul 22, 2019

@mosra mosra added this to TODO in GUI via automation Jul 22, 2019

@mosra

This comment has been minimized.

Copy link
Owner

commented Jul 22, 2019

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 d774aeb 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 8408dd2, 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.

@Melix19

This comment has been minimized.

Copy link
Author

commented Jul 24, 2019

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.

@Melix19 Melix19 closed this Jul 24, 2019

GUI automation moved this from TODO to Done Jul 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.