Change font in ofxImGui

Hi all
I’m testing the addon ofxImGui which is amazing.
I have troubles adding a new font with this simple example. It compiles but font is still default.

gui.setup();
    //imageButtonSource.load("of.png");
    imageButtonID = gui.loadImage(imageButtonSource);
    ImGuiIO& io = ImGui::GetIO();
    
    ImFontConfig config;
    config.OversampleH = 3;
    config.OversampleV = 1;
    config.GlyphExtraSpacing.x = 1.0f;
    io.Fonts->AddFontFromFileTTF("/Users/David/Openframeworks/apps/myApps/imGui/bin/data/fonts/Telefonica-Regular.ttf", 28.0f, &config);
    
   // font1 = io.Fonts->AddFontDefault();
    //font1 = io.Fonts->AddFontFromFileTTF("/Users/David/Openframeworks/apps/myApps/imGui/bin/data/fonts/Verdana.ttf", 18.0f);
    
   // ImGui::Fonts->GetTexDataAsRGBA32;
 
}

//--------------------------------------------------------------
void ofApp::update(){

}
ImVec4 clear_color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
//--------------------------------------------------------------
void ofApp::draw(){
    //required to call this at beginning
    gui.begin();

    bool show_another_window = true;
    ImGui::SetNextWindowSize(ofVec2f(400,400), ImGuiSetCond_FirstUseEver);
    ImGui::SetNextWindowPos(ofVec2f(100,100));
    ImGui::Begin("Final Result", &show_another_window);
    ImGui::BeginChild("Scrolling");
    ImGui::SetWindowFontScale(2.5f);
   // ImGui::PushFont(font1);
    for (int n = 0; n < 50; n++)
        ImGui::TextColored(clear_color, "%04d: Some text");
    ImGui::EndChild();
    //ImGui::PopFont();
    
    //ImGui::ImageButton((ImTextureID)(uintptr_t)imageButtonID, ImVec2(300, 300));
    ImGui::End();
    gui.end();
}

Take a look at example-demo in my fork of the addon.
There is shown how you can set the default font.

it gives me the same error I have in the simple test:
IM_ASSERT(0); // Could not load file.

it might be related to my os? MacOsX 10.13.3

Yes, as I remember there is something with paths to data folder on MacOs. Search for this topic.
Something like this


or
this

Sorry, I am not a MacOs guy but I remember something like this. When you have a compiled version of your app, you have data folder and application. Right click on it -> Show Package Contents -> and run app from Contents\MacOS\applicationName. It should work then. I think there is some option in Xcode to set it.

Did you handle it?

Hey yes!
Just Mac / resolved the thing.

int indexFontA = gui.addFont("fonts/Verdana.ttf", 15);
int indexFontB = gui.addFont("fonts/RobotoSlab-Regular.ttf", 20);
gui.SetDefaultFont(indexFontA);

With the horrible option of absolute path, worked as well:

ImFontConfig config;
config.OversampleH = 3;
config.OversampleV = 1;
config.GlyphExtraSpacing.x = 1.0f;
io.Fonts->AddFontFromFileTTF("/Users/David/Openframeworks/apps/myApps/imGui/bin/data/fonts/Telefonica-Regular.ttf", 32.0f, &config);

Your example was the solution.

Third way, as well from your examples:

ImGuiIO& io = ImGui::GetIO();
string inputPath;
inputPath = ofFilePath::getAbsolutePath("fonts/Telefonica-Regular.ttf");
const char* myPath = inputPath.c_str();
ImFontConfig config;
config.OversampleH = 3;
config.OversampleV = 1;
config.GlyphExtraSpacing.x = 1.0f;
io.Fonts->AddFontFromFileTTF(myPath, 32.0f, &config);
2 Likes