ofxImGui icon indicating copy to clipboard operation
ofxImGui copied to clipboard

Could not change fonts

Open genleung opened this issue 7 years ago • 6 comments

I try to load a CJK font after gui.setup() :

void ofApp::setup() { ofSetLogLevel(OF_LOG_VERBOSE); //required call gui.setup(); ImGui::GetIO().MouseDrawCursor = false; // Load Fonts ImFontConfig font_config; ImGuiIO& io = ImGui::GetIO(); //ImGui::PopFont(); if(io.Fonts->AddFontFromFileTTF("notosans.otf", 15.0f, &font_config, io.Fonts ->GetGlyphRangesChinese())){ std::cout<<"********* Font loaded!"<<std::endl; }else{ std::cout<<"xxxxxxxxx Font failed to load!"<<std::endl; } // ......................

It seems that the font could be loaded, but the whole window texts remain the same as the original look. These code lines actually work well in the ImGui opengl demo examples.

And I try to load fonts in EngineGLFW.cpp:

bool EngineGLFW::createFontsTexture() { // Build texture atlas ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; io.Fonts->AddFontFromFileTTF("notosans.otf", 15.0f, &font_config, io.Fonts ->GetGlyphRangesChinese()) io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // .............

This time, it got crashed by a segmentation fault.

I also tried to load another Latin-based font like ProggyClean.ttf companied with ImGui, and the problem remains the same.

genleung avatar May 15 '17 02:05 genleung

I can confirm this bug

sphaero avatar Jun 14 '18 07:06 sphaero

A workaround is to build the font before setup()

ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontDefault();
io.Fonts->AddFontFromFileTTF("Roboto-Medium.ttf", 16.0f);
gui.setup();

sphaero avatar Jun 14 '18 07:06 sphaero

yes, font loading need to be done before setting up the gui. Confirm this issue also.

xarthurx avatar Feb 19 '19 12:02 xarthurx

Tried this, and been through all the docs I can find and cannot load any fonts. Crashes because it can';t find or load font??? Hmmm...

Would love too know how you get fonts to load.

------------------ this didn't work:

A workaround is to build the font before setup()

ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.Fonts->AddFontDefault(); io.Fonts->AddFontFromFileTTF("Roboto-Medium.ttf", 16.0f); gui.setup();

steeley avatar Oct 22 '19 18:10 steeley