failing to run my UI after using a new font #7043
Replies: 1 comment 4 replies
-
There are quite a few problems with your code, I suggest looking at the example code to learn the structure of Dear ImGui. Problem 1
That means it crashed, don't "run without debug", simply hit F5 and attach the debugger. If you did that, you could see that it'll throw an error in imgui_draw.cpp: IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!"); The error is pretty self-explanatory, in your second picture, you tried to add a font between Problem 2The original code uses a lot of fonts, which are You must initialize them all, or remove what uses them. I suggest adding this, just to make it runnable: ImFont* newFont = io.Fonts->AddFontFromFileTTF("C:\\Users\\Famito\\Desktop\\police\\Pacifico.ttf", 16);
tab_text1 = nullptr;
tab_text2 = nullptr;
tab_text3 = nullptr;
ico = nullptr;
ico_2 = nullptr;
ico_subtab = nullptr;
ico_logo = nullptr;
tab_text = nullptr;
ico_minimize = nullptr; Once that works, you should initialize them with the fonts you want, and optionally remove fonts you don't intend to use and their related code. Problem 3You correctly used |
Beta Was this translation helpful? Give feedback.
-
i have recently bought a C++ UI on internet, i am kinda very new to développement and i dont have a large knowledge of C++.
after a few hours customizing the UI and changing all colors and text etc i now want to add a new font to the UI because the one used is kinda simple.
with the help of chat gpt iv'e learn a lot and see that i need to use the fonction AddFontFromFileTTF wich is what iv'e done.
the problem is that the old font is loaded from AddFontFromMemoryTTF, after trying a lot of option to run the new font, none of them have been successful.
on a copy project iv'e tried to delete the Inter.h include wich is the old font used and all the place where Inter or &inter is used after seing that removing this:
io.Fonts->AddFontFromMemoryTTF(&inter, sizeof inter, 16 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
tab_text1 = io.Fonts->AddFontFromMemoryTTF(&inter, sizeof inter, 12 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
tab_text2 = io.Fonts->AddFontFromMemoryTTF(&inter, sizeof inter, 24 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
tab_text3 = io.Fonts->AddFontFromMemoryTTF(&inter, sizeof inter, 40 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
ico = io.Fonts->AddFontFromMemoryTTF(&icon, sizeof icon, 25 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
ico_2 = io.Fonts->AddFontFromMemoryTTF(&Menuicon, sizeof Menuicon, 20 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
ico_subtab = io.Fonts->AddFontFromMemoryTTF(&icon, sizeof icon, 35 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
ico_logo = io.Fonts->AddFontFromMemoryTTF(&icon, sizeof icon, 31 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
tab_text = io.Fonts->AddFontFromMemoryTTF(&inter, sizeof inter, 19 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
ico_minimize = io.Fonts->AddFontFromMemoryTTF(&icon, sizeof icon, 27 * dpi_scale, NULL, io.Fonts->GetGlyphRangesCyrillic());
ImGui::StyleColorsDark();
get me back to default font.
The problem i encounter now is that when i click on 'run without debug" the UI examples dont appear and let me with a white screen that close after a second.
my font seems to be correctly loaded with:
void InitializeImGui() {
// Charger la nouvelle police depuis un fichier TTF
const char* newFontPath = "C:\Users\Famito\Desktop\police\Pacifico.ttf";
ImGuiIO& io = ImGui::GetIO();
ImFont* newFont = io.Fonts->AddFontFromFileTTF(newFontPath, 1);
if (newFont) {
// La nouvelle police a été chargée avec succès
printf("Nouvelle police chargée avec succès!\n");
}
else {
// Échec du chargement de la nouvelle police
printf("Échec du chargement de la nouvelle police.\n");
}
ImGui::GetIO().FontDefault = newFont;
and after that iv'e used : ImGui::PushFont(newFont); before and ImGui::PopFont(); after all fonction where ImGui and a text is added.
lmk if any other information/screeshot or spécification is needed.
THANKS FOR THOSE WHO READ THIS !
Beta Was this translation helpful? Give feedback.
All reactions