jvcleave / ofxImGui

Use ImGui in openFrameworks
293 stars 124 forks source link

Could not change fonts #52

Open genleung opened 7 years ago

genleung commented 7 years ago

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.

sphaero commented 6 years ago

I can confirm this bug

sphaero commented 6 years ago

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();
xarthurx commented 5 years ago

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

steeley commented 4 years ago

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();