ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.8k stars 298 forks source link

"How to display UTF-8 encoded text using ImGui.NET in C#" #474

Open HuaChenDu opened 2 months ago

HuaChenDu commented 2 months ago

Resolving the issue of UTF-8 strings displaying as '??????' 屏幕截图 2024-04-23 085923 屏幕截图 2024-04-23 085800 屏幕截图 2024-04-23 085945

HuaChenDu commented 2 months ago

屏幕截图 2024-04-23 090336 屏幕截图 2024-04-23 090400 I attempt to solve using the mindset of C++ code, or to display???

mellinoe commented 2 months ago

You need to do something like what is described here: https://github.com/ImGuiNET/ImGui.NET/issues/67

HuaChenDu commented 2 months ago

You need to do something like what is described here: #67 I still don't understand. Could you teach me how to modify my code? my code: namespace ImGuiNET { public class Program : Overlay { bool checkBoxValue = false; int loveMeter = 0; string input = ""; string input2 = ""; bool showWindow = true;

    protected override void Render()
    {
        ImGui.Begin("XuanYuFuZhu",  ref checkBoxValue);

        string chineseText = "这里显示中文";
        ImGui.Text(chineseText);

        if (!showWindow)
        {
            System.Environment.Exit(0);
        }
    }

    public void CloseWindowAndExit()
    {
        showWindow = false;
    }

    public static void Main(string[] args)
    {
        Program program = new Program();
        program.Start().Wait();
    }
}

}

HuaChenDu commented 2 months ago

You need to do something like what is described here: #67

![Uploading 屏幕截图 2024-04-24 164844.png…]() Thank you very much for your help. After 2 days of trial and error, I added this line 'ImGui.CreateContext();' on top of the method you provided, and now it can display Chinese characters.

abo-nb commented 2 months ago

Can you provide the code? Thanks!