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
Hello,
I’m using XCode 3.2.6 and when I execute a compiled application (e.g. myExample.app or myExampleDebug.app) the files stored in ‘data’ folder are not loaded. Details are given below.
All my files are stored in ‘(Some_Folder)/of_v0.7.4_osx_release/apps/myApps/myExample/bin/data/’ and when I access to them I use the following relative path:
“./data/file.txt” when I use ifstream (e.g. to load some parameters);
“videofile.avi” when I use loadMovie from ofVideoPlayer class.
When I click on…
or
this
Thank you again for your help!
I tried manually copying the data folder (generated on the device with a 0.8.0-equivalent app compiled), but with no luck; also tried to lower-case everything… still same errors…
Then I tried all the android examples included with the master, and I can confirm that only the ones without data worked; any of the other can’t find resources (and their data folders are actually empty) and gave me the usual errors in the log cat (“couldn’t find file…” etc…)
it’s reall…
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.
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