-
Notifications
You must be signed in to change notification settings - Fork 1
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
How to perform an AddFontFromMemoryTTF instead of addFont/AddFontFromFileTTF #13
Comments
Hey Manu, It looks like the .cpp file is a TTF file too, they're just using ofxImGui uses Line 272 in ab228a6
So I think it would make sense to duplicate the Line 40 in ab228a6
On the other side, you might not need to modify ofxImGui, you could call the I got to load the ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false;
gui.addFontFromMemory((void*)tahoma, sizeof(tahoma), 17.f, &font_cfg);
// ImGui::MergeIconsWithLatestFont(16.f, false); |
cool thanks, @Daandelange It worked after adding the memory-based addFont method I was getting crashes, black panels, and white squares on fonts. I copy pasted it here just in case or do you prefer a pull maybe? Gui.h public:
ImFont* addFont(void* ttf_data, int ttf_size, float fontSize = 13.0f, const ImFontConfig* _fontConfig = nullptr, const ImWchar* _glyphRanges = nullptr, bool _setAsDefaultFont = false); Gui.cpp //--------------------------------------------------------------
ImFont* Gui::addFont(void* ttf_data, int ttf_size, float fontSize, const ImFontConfig* _fontConfig, const ImWchar* _glyphRanges, bool _setAsDefaultFont) {
if (context == nullptr) {
ofLogWarning() << "You must load fonts after gui.setup() ! (ignoring this call)";
return nullptr;
}
//ImFontConfig structure allows you to configure oversampling.
//By default OversampleH = 3 and OversampleV = 1 which will make your font texture data 3 times larger
//than necessary, so you may reduce that to 1.
ImGui::SetCurrentContext(context);
ImGuiIO& io = ImGui::GetIO();
//std::string filePath = ofFilePath::getAbsolutePath(fontPath);
// ensure default font gets loaded once
if (io.Fonts->Fonts.size() == 0) io.Fonts->AddFontDefault();
ImFont* font = io.Fonts->AddFontFromMemoryTTF(ttf_data, ttf_size, fontSize, _fontConfig, _glyphRanges);
if (io.Fonts->Fonts.size() > 0) {
io.Fonts->Build();
if (engine.updateFontsTexture()) {
if (_setAsDefaultFont) setDefaultFont(font);
return font;
}
else return nullptr;
}
else {
return nullptr;
}
} |
Hey, Yes it already is committed to develop (0c12244), I thought you'd see the mention above your post... |
AddFontFromMemory fonts-example (commented). #13
Hello @Daandelange ,
I am trying to integrate that repo:
https://github.com/patrickcjk/imgui-notify
--
It's working well here on nightly builds, as uses C++17.
But I am not being able to enable the font icons.
(without crashing or breaking the atlas to white squares)
The repo adds the fonts as cpp .h files instead as in your implemented method to load ttf files:
customFont = gui.addFont("Roboto-Medium.ttf",16.f, nullptr, true?polishCharRanges:normalCharRanges);
ImFont* font = io.Fonts->AddFontFromFileTTF(filePath.c_str(), fontSize, _fontConfig, _glyphRanges);
--
Do you have any clue to make that work?
Here are some notes by the author:
And the code that must be initiated in some way:
Initialisation (after impl call, e.g ImGui_ImplDX12_Init)
--
I am trying to figure out something here, but no success:
https://github.com/ocornut/imgui/blob/master/docs/FONTS.md
https://github.com/Daandelange/ofxImGui/tree/master/example-fonts
Regards
The text was updated successfully, but these errors were encountered: