Browse Source

Fonts: update misc comments, docs.

ocornut 3 months ago
parent
commit
115a8e74c2
3 changed files with 26 additions and 14 deletions
  1. 1 1
      .github/ISSUE_TEMPLATE/issue_template.yml
  2. 2 1
      docs/FONTS.md
  3. 23 12
      imgui.cpp

+ 1 - 1
.github/ISSUE_TEMPLATE/issue_template.yml

@@ -4,7 +4,7 @@ body:
   - type: markdown
   - type: markdown
     attributes:
     attributes:
       value: |
       value: |
-        FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING or LOADING FONTS, please use [GitHub Discussions](https://github.com/ocornut/imgui/discussions)
+        FOR FIRST-TIME USERS ISSUES COMPILING/LINKING/RUNNING, please use [GitHub Discussions](https://github.com/ocornut/imgui/discussions)
         For anything else: **we are happy to use 'GitHub Issues' for many types of open-ended questions**. We are encouraging 'Issues' becoming a large, centralized, tagged, cross-referenced database of Dear ImGui contents.
         For anything else: **we are happy to use 'GitHub Issues' for many types of open-ended questions**. We are encouraging 'Issues' becoming a large, centralized, tagged, cross-referenced database of Dear ImGui contents.
 
 
         Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users.
         Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users.

+ 2 - 1
docs/FONTS.md

@@ -105,6 +105,7 @@ io.Fonts->AddFontDefault();
 ```
 ```
 
 
 **Load .TTF/.OTF file with:**
 **Load .TTF/.OTF file with:**
+
 🆕 **Since 1.92, with an up to date backend: passing a size is not necessary**
 🆕 **Since 1.92, with an up to date backend: passing a size is not necessary**
 ```cpp
 ```cpp
 ImGuiIO& io = ImGui::GetIO();
 ImGuiIO& io = ImGui::GetIO();
@@ -377,7 +378,7 @@ TL;DR; With the new system, it is recommended that you create a custom `ImFontLo
 
 
 You can ask questions in [#8466](https://github.com/ocornut/imgui/issues/8466).
 You can ask questions in [#8466](https://github.com/ocornut/imgui/issues/8466).
 
 
-🆕 **Before 1.92:**
+**Before 1.92:**
 
 
 As an alternative to rendering colorful glyphs using imgui_freetype with `ImGuiFreeTypeBuilderFlags_LoadColor`, you may allocate your own space in the texture atlas and write yourself into it. **(This is a BETA api, use if you are familiar with dear imgui and with your rendering backend)**
 As an alternative to rendering colorful glyphs using imgui_freetype with `ImGuiFreeTypeBuilderFlags_LoadColor`, you may allocate your own space in the texture atlas and write yourself into it. **(This is a BETA api, use if you are familiar with dear imgui and with your rendering backend)**
 
 

+ 23 - 12
imgui.cpp

@@ -21,9 +21,10 @@
 // - Issues & support ........... https://github.com/ocornut/imgui/issues
 // - Issues & support ........... https://github.com/ocornut/imgui/issues
 // - Test Engine & Automation ... https://github.com/ocornut/imgui_test_engine (test suite, test engine to automate your apps)
 // - Test Engine & Automation ... https://github.com/ocornut/imgui_test_engine (test suite, test engine to automate your apps)
 
 
-// For first-time users having issues compiling/linking/running/loading fonts:
+// For first-time users having issues compiling/linking/running:
 // please post in https://github.com/ocornut/imgui/discussions if you cannot find a solution in resources above.
 // please post in https://github.com/ocornut/imgui/discussions if you cannot find a solution in resources above.
 // Everything else should be asked in 'Issues'! We are building a database of cross-linked knowledge there.
 // Everything else should be asked in 'Issues'! We are building a database of cross-linked knowledge there.
+// Since 1.92, we encourage font loading question to also be posted in 'Issues'.
 
 
 // Copyright (c) 2014-2025 Omar Cornut
 // Copyright (c) 2014-2025 Omar Cornut
 // Developed by Omar Cornut and every direct or indirect contributors to the GitHub.
 // Developed by Omar Cornut and every direct or indirect contributors to the GitHub.
@@ -347,12 +348,12 @@ CODE
         ImGui::Render();
         ImGui::Render();
 
 
         // Update textures
         // Update textures
-        for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
+        ImDrawData* draw_data = ImGui::GetDrawData();
+        for (ImTextureData* tex : *draw_data->Textures)
             if (tex->Status != ImTextureStatus_OK)
             if (tex->Status != ImTextureStatus_OK)
                 MyImGuiBackend_UpdateTexture(tex);
                 MyImGuiBackend_UpdateTexture(tex);
 
 
         // Render dear imgui contents, swap buffers
         // Render dear imgui contents, swap buffers
-        ImDrawData* draw_data = ImGui::GetDrawData();
         MyImGuiBackend_RenderDrawData(draw_data);
         MyImGuiBackend_RenderDrawData(draw_data);
         SwapBuffers();
         SwapBuffers();
      }
      }
@@ -372,25 +373,32 @@ CODE
     {
     {
         if (tex->Status == ImTextureStatus_WantCreate)
         if (tex->Status == ImTextureStatus_WantCreate)
         {
         {
-            // create texture based on tex->Width/Height/Pixels
-            // call tex->SetTexID() to specify backend-specific identifiers
-            // tex->Status = ImTextureStatus_OK;
+            // <create texture based on tex->Width/Height/Pixels>
+            tex->SetTexID(xxxx); // specify backend-specific ImTextureID identifier
+            tex->SetStatus(ImTextureStatus_OK);
+            tex->BackendUserData = xxxx; // store more backend data
         }
         }
         if (tex->Status == ImTextureStatus_WantUpdates)
         if (tex->Status == ImTextureStatus_WantUpdates)
         {
         {
-            // update texture blocks based on tex->UpdateRect
-            // tex->Status = ImTextureStatus_OK;
+            // <update texture blocks based on tex->UpdateRect>
+            tex->SetStatus(ImTextureStatus_OK);
         }
         }
         if (tex->Status == ImTextureStatus_WantDestroy)
         if (tex->Status == ImTextureStatus_WantDestroy)
         {
         {
-            // destroy texture
-            // call tex->SetTexID(ImTextureID_Invalid)
-            // tex->Status = ImTextureStatus_Destroyed;
+            // <destroy texture>
+            tex->SetTexID(ImTextureID_Invalid);
+            tex->SetStatus(ImTextureStatus_Destroyed);
         }
         }
     }
     }
 
 
     void MyImGuiBackend_RenderDrawData(ImDrawData* draw_data)
     void MyImGuiBackend_RenderDrawData(ImDrawData* draw_data)
     {
     {
+       if (draw_data->Textures != nullptr)
+           for (ImTextureData* tex : *draw_data->Textures)
+               if (tex->Status != ImTextureStatus_OK)
+                   MyImGuiBackend_UpdateTexture(tex);
+
+
        // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
        // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
        // TODO: Setup texture sampling state: sample with bilinear filtering (NOT point/nearest filtering). Use 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines;' to allow point/nearest filtering.
        // TODO: Setup texture sampling state: sample with bilinear filtering (NOT point/nearest filtering). Use 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines;' to allow point/nearest filtering.
        // TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
        // TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
@@ -407,7 +415,10 @@ CODE
              const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
              const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
              if (pcmd->UserCallback)
              if (pcmd->UserCallback)
              {
              {
-                 pcmd->UserCallback(cmd_list, pcmd);
+                 if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+                     MyEngineResetRenderState();
+                 else
+                     pcmd->UserCallback(cmd_list, pcmd);
              }
              }
              else
              else
              {
              {