LoginSignup
20

More than 5 years have passed since last update.

imgui で日本語が「?」になる場合の対処

Posted at

imgui で日本語を表示する際、以下のようにします。

ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("フォントのパス", 10.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());

これで日本語を表示していると、たまに「?」になってしまう文字があります。
例えば「瞳」などです。

「?」になる原因

これは、io.Fonts->GetGlyphRangesJapanese() で取得できるグリフの範囲が JIS X 0208 で表示できるものより狭いことにあるようです。

対処法

JIS X 0208 で表示できる文字すべてを登録すればよいので、以下を参考にグリフの範囲を作成します。

ftp://ftp.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/JIS0208.TXT

出来上がる配列は量が多いので、こちらに張り付けておきました。

これを次のように使います。

ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("フォントのパス", 10.0f, nullptr, glyphRangesJapanese);

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20