Flix01 / imgui

Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
https://github.com/Flix01/imgui/wiki/ImGui-Addons-Branch-Home
MIT License
396 stars 34 forks source link

Adding Font icons example doesn't work for me. #63

Closed jillingb closed 2 years ago

jillingb commented 2 years ago

Hello!

I have problems with Loading icon fonts but only using this AddOns(GLUT binding). In the imgui examples I could add FontAwesome icons and display everything properly. Here on the other hand I did the example the same way as recommended:

int ImImpl_Main(const ImImpl_InitParams* pOptionalInitParams,int argc, char** argv) { if (!InitBinding(pOptionalInitParams, argc, argv)) return -1; IMGUI_CHECKVERSION(); ImGui::CreateContext(); InitImGui(pOptionalInitParams); ImGuiIO& io = ImGui::GetIO(); here starts io.Fonts->AddFontDefault(); it's not actually needed here ImFontConfig config; config.MergeMode = true; config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; auto new_font = io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, icon_ranges); .... After that I get Assert error, I can set the TexReady to true, then it runs but the texture is not actually rebuilt. So I tried calling io.Fonts->Build(); It has no more errors but everything is gone, it starts but nothing is drawn. I saw in this issue: https://github.com/ocornut/imgui/issues/2311 but I don't know how to invalidate in GLUT.

So i guess I'm having some difficultuies understanding the imguibindings.cpp.

Long story short, how could I add a font here with icons using the GLUT bindings? I also tried with this method: AddFontFromMemoryTTFCloningFontData(..) but this is basically similar to AddFontFromFileTTF and I couldn't make it work.

Thank you in advance! btw the NodeEditor is pretty awesome!

Flix01 commented 2 years ago

The second example (WebGL demo here) uses FontAwesome icons by default and it should work with any binding. 1-nq8

You can look at its main function here.

Basically the code merges (an inline version of) DejaVuSerifCondensed-Bold.ttf (used for text) and FontAwesome icons (the definition TEST_ICONS_INSIDE_TTF is enabled by default). You can ignore the code guarded by if (!defined(NO_IMGUICODEEDITOR) && !defined(NO_IMGUIFILESYSTEM)), that adds (an inline version of) DejaVuSansMono-Bold-Stripped.ttf as a secondary font for imguicodeeditor.

Seems to work for me, regardless of the binding.

jillingb commented 2 years ago

Now it's working for me too. The issue came from calling orders of the font loading, with your code handles it properly. Thank you for the quick reply and help!