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

error to show many text after AddFontFromFileTTF #6251

Closed
zdy-gggg opened this issue Mar 17, 2023 · 11 comments
Closed

error to show many text after AddFontFromFileTTF #6251

zdy-gggg opened this issue Mar 17, 2023 · 11 comments
Labels

Comments

@zdy-gggg
Copy link

My Issue/Question:
How do I show many text after AddFontFromFileTTF?

I need show many text the same time using ImGuI::Text()

I've adopted the code to my needs:

ImGui::Begin("Another Window", &show_another_window);
ImGui::SetWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetWindowSize(ImVec2(nW, nH));
for (int y = 0; y < 50; ++y)
{
      for (int x = 0; x < 100; ++x)
       {
             ImGui::Text("Test");
              ImGui::SameLine();
        }
       ImGui::Text("TestEnd");
}
ImGui::End();

This works correctly with the default font
image

but If I load the font such as io.Fonts->AddFontFromFileTTF( "Imgui\\misc\\fonts\\Roboto-Medium.ttf",10, NULL);
image

@PathogenDavid
Copy link
Contributor

This has come up before but I can't for the life of me remember what the underlying cause was. I think it was due to an outdated backend and/or a buggy custom backend.

It would be helpful if you filled out the issue template, particularly the parts about what version of Dear ImGui and what backends you're using.

@zdy-gggg
Copy link
Author

This has come up before but I can't for the life of me remember what the underlying cause was. I think it was due to an outdated backend and/or a buggy custom backend.

It would be helpful if you filled out the issue template, particularly the parts about what version of Dear ImGui and what backends you're using.

Thank you for your reply

Version/Branch of Dear ImGui:
Version: 1.89 WIP
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: MSVS 2019
Operating System: Windows 11

@PathogenDavid
Copy link
Contributor

Thank you for providing those details!

Are you using an Intel GPU?

And either way: Can you please try updating your drivers and see if the issue goes away?


This appears to be related to #5617, #5655, and #5709 (comment)

I think we've been assuming those were related to #4832, but you're using a version of Dear ImGui that was supposed to fix 4832...so maybe not.

@zdy-gggg
Copy link
Author

Thank you for providing those details!

Are you using an Intel GPU?

And either way: Can you please try updating your drivers and see if the issue goes away?

This appears to be related to #5617, #5655, and #5709 (comment)

I think we've been assuming those were related to #4832, but you're using a version of Dear ImGui that was supposed to fix 4832...so maybe not.

Thank you for your reply
My GPU is RTX3060 and I think I'm using the latest driver
Sorry, I provided the wrong version information. Previously, I used imgui_ impl_ opengl2.cpp。
It can work normally after using imgui_impl_opengl3.cpp

Thank you for your help

@GamingMinds-DanielC
Copy link
Contributor

GamingMinds-DanielC commented Mar 20, 2023

That much text definitely exceeds what 16 bit indices can do in a single batch (50 lines * 407 chars * 4 vertices = 81400 vertices). With the non-default font at least, with the default one enough seems to be clipped out to make it fit again. If you draw shorter, but more lines, it should happen with the default font as well. Switching to 32 bit indices should circumvent the problem.

@ocornut
Copy link
Owner

ocornut commented Mar 20, 2023

You should have gotten an assert for that, if your build setup doesn't show assert you are going to have severe problems using this library.

@PathogenDavid
Copy link
Contributor

In addition to what Daniel and Omar pointed out: Is there a reason you were using the legacy imgui_impl_opengl2 backend? It really only exists for utterly ancient codebases and as Daniel pointed out it doesn't support large meshes unless you enable 32-bit indices.

@zdy-gggg
Copy link
Author

In addition to what Daniel and Omar pointed out: Is there a reason you were using the legacy imgui_impl_opengl2 backend? It really only exists for utterly ancient codebases and as Daniel pointed out it doesn't support large meshes unless you enable 32-bit indices.

Thank you for your reply
I tried to modify ImDrawIdx To use 32-bit indexes(typedef unsigned int ImDrawIdx;),but whether you use the default font or AddFontFromFileTTF。
The operation results are as follows
image

@zdy-gggg
Copy link
Author

You should have gotten an assert for that, if your build setup doesn't show assert you are going to have severe problems using this library.

Thank you for your suggestion. I'll try something

@ocornut
Copy link
Owner

ocornut commented Mar 21, 2023

To use 32-bit indexes(typedef unsigned int ImDrawIdx;)

Are you sure you put this typedef in imconfig.h and not elsewhere?
It's very important to ensure your assert work (e.g. IM_ASSERT(0) should abort your documentation) otherwise you are working with little safeguard for mistakes.

@ocornut
Copy link
Owner

ocornut commented Mar 22, 2023

Closing as generally answered. Feel free to post details or further things here if needed.

@ocornut ocornut closed this as completed Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants