Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not change fonts #52

Open
genleung opened this issue May 15, 2017 · 6 comments
Open

Could not change fonts #52

genleung opened this issue May 15, 2017 · 6 comments
Labels
legacy-version For issues releated to the older legacy code, before all the refactorings in the develop branch.

Comments

@genleung
Copy link

genleung commented May 15, 2017

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
Copy link
Contributor

sphaero commented Jun 14, 2018

I can confirm this bug

@sphaero
Copy link
Contributor

sphaero commented Jun 14, 2018

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
Copy link

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

@steeley
Copy link

steeley commented Oct 22, 2019

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

@Daandelange Daandelange added the legacy-version For issues releated to the older legacy code, before all the refactorings in the develop branch. label Jul 28, 2024
@tom-leamon
Copy link

I'm still experiencing this issue. I tried @sphaero's workaround, but I can't change from the default monospace font. Is this still a known issue?

@Daandelange
Copy link
Collaborator

It should work like charm in the develop branch, legacy has not evolved for a while ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-version For issues releated to the older legacy code, before all the refactorings in the develop branch.
Projects
None yet
Development

No branches or pull requests

6 participants