Browse Source

don't auto load fonts for ImGui low level API, add font loading to the low level API example

Jeffery Myers 1 year ago
parent
commit
57e55c3a8f
4 changed files with 12 additions and 10 deletions
  1. 6 3
      examples/imgui_style_example.cpp
  2. 1 0
      imgui_impl_raylib.h
  3. BIN
      resources/driusstraight.ttf
  4. 5 7
      rlImGui.cpp

+ 6 - 3
examples/imgui_style_example.cpp

@@ -39,14 +39,17 @@ int main(int, char**)
     // - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
     // - Read 'docs/FONTS.md' for more instructions and details.
     // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
-    //io.Fonts->AddFontDefault();
+    io.Fonts->AddFontDefault();
     //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
     //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
-    //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
-    //IM_ASSERT(font != nullptr);
+    ImFont* font = io.Fonts->AddFontFromFileTTF("resources/driusstraight.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
+    IM_ASSERT(font != nullptr);
 
+    // required to be called to cache the font texture with raylib
+    Imgui_ImplRaylib_BuildFontAtlas();
+   
     // Our state
     bool show_demo_window = true;
     bool show_another_window = false;

+ 1 - 0
imgui_impl_raylib.h

@@ -45,6 +45,7 @@
 #ifndef IMGUI_DISABLE
 
 IMGUI_IMPL_API bool ImGui_ImplRaylib_Init();
+IMGUI_IMPL_API void Imgui_ImplRaylib_BuildFontAtlas();
 IMGUI_IMPL_API void ImGui_ImplRaylib_Shutdown();
 IMGUI_IMPL_API void ImGui_ImplRaylib_NewFrame();
 IMGUI_IMPL_API void ImGui_ImplRaylib_RenderDrawData(ImDrawData* draw_data);

BIN
resources/driusstraight.ttf


+ 5 - 7
rlImGui.cpp

@@ -599,20 +599,18 @@ bool ImGui_ImplRaylib_Init()
 
 	SetupKeymap();
 
-	ImGuiIO& io = ImGui::GetIO();
-	io.Fonts->AddFontDefault();
-
-    SetupFontAwesome();
-
 	SetupMouseCursors();
 
     SetupBackend();
 
-    ReloadFonts();
-
     return true;
 }
 
+void Imgui_ImplRaylib_BuildFontAtlas()
+{
+    ReloadFonts();
+}
+
 void ImGui_ImplRaylib_Shutdown()
 {
     ImGuiIO& io =ImGui::GetIO();