Custom Font is loading as white rectangle #6632

Closed
opened 2023-07-22 11:34:06 +00:00 by luis605 · 3 comments
luis605 commented 2023-07-22 11:34:06 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.89.2
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: rlImGui
Compiler: g++
Operating System: Linux Mint 21.1 Vera

My Issue/Question:

I decided to change dear imgui default font to Poppins Regular as follow:

    ImFontConfig fontConfig;
    fontConfig.FontDataOwnedByAtlas = false;

    std::string fontPath = GetWorkingDirectory();
    fontPath += "/assets/fonts/Poppins-Regular.ttf";
    std::cout << fontPath << std::endl;

    ImFont* robotoFont = io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 20.0f, &fontConfig);
    io.FontDefault = robotoFont;
    io.Fonts->Build();

The font is added without any error or warning, but in the dear imgui window, every character is represented by a white rectangle. The screenshot below shows my current issue.

Screenshots/Video

imagem

Standalone, minimal, complete and verifiable example:

#include "include/raylib.h"

#include "imgui/imgui.h"
#include "imgui/imgui_internal.h"
#include "include/rlImGui.h"

#include <string>
#include <iostream>

using namespace std;


int main() {
    InitWindow(500, 500, "Example");

    // ImGui
    rlImGuiSetup(true);

    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();

    ImFontConfig fontConfig;
    fontConfig.FontDataOwnedByAtlas = false;

    std::string fontPath = GetWorkingDirectory();
    fontPath += "/assets/fonts/Poppins-Regular.ttf";
    std::cout << fontPath << std::endl;

    ImFont* robotoFont = io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 20.0f, &fontConfig);
    io.FontDefault = robotoFont;
    io.Fonts->Build();


    while (!WindowShouldClose()) {
        BeginDrawing();

            ClearBackground(DARKGRAY);

            rlImGuiBegin();

            ImGui::Begin("Test");
            ImGui::Text("Hello, world!");
            ImGui::End();

            rlImGuiEnd();

        EndDrawing();
    }
}

Font Downloaded from here: https://fonts.google.com/specimen/Poppins

**Version/Branch of Dear ImGui:** Version: 1.89.2 Branch: docking **Back-end/Renderer/Compiler/OS** Back-ends: rlImGui Compiler: g++ Operating System: Linux Mint 21.1 Vera **My Issue/Question:** I decided to change dear imgui default font to Poppins Regular as follow: ```cpp ImFontConfig fontConfig; fontConfig.FontDataOwnedByAtlas = false; std::string fontPath = GetWorkingDirectory(); fontPath += "/assets/fonts/Poppins-Regular.ttf"; std::cout << fontPath << std::endl; ImFont* robotoFont = io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 20.0f, &fontConfig); io.FontDefault = robotoFont; io.Fonts->Build(); ```` The font is added without any error or warning, but in the dear imgui window, every character is represented by a white rectangle. The screenshot below shows my current issue. **Screenshots/Video** ![imagem](https://github.com/ocornut/imgui/assets/60551627/511843bd-fc93-492b-8e11-5838c926a232) **Standalone, minimal, complete and verifiable example:** ```cpp #include "include/raylib.h" #include "imgui/imgui.h" #include "imgui/imgui_internal.h" #include "include/rlImGui.h" #include <string> #include <iostream> using namespace std; int main() { InitWindow(500, 500, "Example"); // ImGui rlImGuiSetup(true); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); ImFontConfig fontConfig; fontConfig.FontDataOwnedByAtlas = false; std::string fontPath = GetWorkingDirectory(); fontPath += "/assets/fonts/Poppins-Regular.ttf"; std::cout << fontPath << std::endl; ImFont* robotoFont = io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 20.0f, &fontConfig); io.FontDefault = robotoFont; io.Fonts->Build(); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(DARKGRAY); rlImGuiBegin(); ImGui::Begin("Test"); ImGui::Text("Hello, world!"); ImGui::End(); rlImGuiEnd(); EndDrawing(); } } ``` Font Downloaded from here: https://fonts.google.com/specimen/Poppins
sakiodre commented 2023-07-22 12:56:11 +00:00 (Migrated from github.com)

I'm unable to replicate this, both FreeType and TrueType, would you mind showing the font atlas?

image

By the way, only set FontDataOwnedByAtlas to false if you load the font from memory.

I'm unable to replicate this, both FreeType and TrueType, would you mind showing the font atlas? ![image](https://github.com/ocornut/imgui/assets/136492105/c5b12f9f-c1cf-4761-ade4-ebd84eced1cb) By the way, only set `FontDataOwnedByAtlas` to `false` if you load the font from memory.
sakiodre commented 2023-07-22 13:17:03 +00:00 (Migrated from github.com)

I'm not familiar with rlImGui but looking at the code, maybe you need to call rlImGuiReloadFonts after io.Fonts->Build();

I'm not familiar with `rlImGui` but looking at the code, maybe you need to call `rlImGuiReloadFonts` after `io.Fonts->Build();`
luis605 commented 2023-07-22 14:19:11 +00:00 (Migrated from github.com)

It was it, rlImGuiReloadFonts() fixed the issue. thank you @sakiodre !

It was it, rlImGuiReloadFonts() fixed the issue. thank you @sakiodre !
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6632
No description provided.