-2

I'm using ImGui, the implementation for OpenGL worked fine but now I have a problem with rendering some Text. For some reason, whenever I try to render a string with ImGui::Text(someString.c_str()); ImGui renders only the first 19 characters. If I try to render the same Text with ImGui::Text("This is a Text longer than 19 characters") ImGui renders the whole Text.

I tried it with also with ImGui::TextUnformatted(&someString[0], &someString[someString.size()-1]);, same result: the first 19 characters are shown, but the rest is cut away.

But if I do std::clog << someString.c_str() it works completly fine.

I would be very glad if someone could spot my mistake, I tried many hours but wasn't able to fix it.

2 Answers2

2

In order for ImGui to render non standard characters, you need to specify the range of characters the font should use, and instruct ImGui to use utf-8 encoding when rendering that font.

Depending on the characters you want to display, you need to add the relative codes according to their utf-8 code pages. Something along the lines of:

const ImWchar*  ImFontAtlas::GetGlyphRangesPolish()
{
    static const ImWchar ranges[] =
    {
        0x0020, 0x00FF, // Basic Latin + Latin Supplement
        0x00A0, 0x02D9, // Polish characters 
        0,
    };
    return &ranges[0];
}

Then you need to add that range to the font you want to use in your program:

ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf", 17.0f, nullptr, io.Fonts->GetGlyphRangesPolish());

Now you can use the additionally imported text characters in ImGui

ImGui::TextWrapped("łąężü");

If you don't use this method, you will display ????? characters instead of the ones you need in ImGui.

enter image description here

JerryWebOS
  • 91
  • 3
1

The Problem was that I never had the Idea to use another string... The content of someString contained a 'ü' which terminated the string. But why 'ü' doesn't work with ImGui is another question.