realgamessoftware / dear-imgui-unity

Unity package for Dear ImGui
MIT License
455 stars 108 forks source link

Problem loading fonts #17

Closed trapazza closed 3 years ago

trapazza commented 3 years ago

Hi there :)

Has anyone managed to load and use a font other than the default one? It's not working for me and have no idea what I'm doing wrong.

This is what I do:

var io = ImGui.GetIO();
io.Fonts.AddFontDefault();
var font = io.Fonts.AddFontFromFileTTF( font_path, font_pixels ); // font stored in a dictionary
io.Fonts.Build();>

I checked that the font is properly loaded (.IsLoaded()), but the result is that all fonts get corrupted (even the default one). In this case I'm not even using the PushFont/PopFont pair.

image

I've seen that there's a FontAtlasConfigAsset struct referenced from the DearImGui script source code, but I don't have access to it from the IDE and there seems to be literally zero information about how it's used.

Thanks everyone in advance.

GoomiiV2 commented 3 years ago

Hey, I got this working for font icons so this is what I did.

In the project explorer the right click context menu should have a "Dear Imgui" option and in there you can create a "Font Atlas Configuration".

In this file you can set up the multiple fonts to use, this is how I have mine for a normal font and then FontAwesome for the icons. image

If you just want to replace the default font then the top entry should just be enough.

Then on the GameObject with the Dear Imgui Script you can set the "Font Atlas Configuration" to the asset created above.

Hopefully that helped abit :>

trapazza commented 3 years ago

Hey, I got this working for font icons so this is what I did.

In the project explorer the right click context menu should have a "Dear Imgui" option and in there you can create a "Font Atlas Configuration".

In this file you can set up the multiple fonts to use, this is how I have mine for a normal font and then FontAwesome for the icons. image

If you just want to replace the default font then the top entry should just be enough.

Then on the GameObject with the Dear Imgui Script you can set the "Font Atlas Configuration" to the asset created above.

Hopefully that helped abit :>

Yes, yes, yes! thanks a lot :))))