提问者:小点点

DrawTextEx不显示unicode字符


我正在尝试使用raylib显示包含西里尔字符的字符串。所以我加载了一个代码点如下的字体:

int codepoints[512] = { 0 };
for (int i = 0; i < 95; i++) codepoints[i] = 32 + i;
for (int i = 0; i < 255; i++) codepoints[96 + i] = 0x400 + i;
Font font = LoadFontEx("arial.ttf", 32, codepoints, 512);

如果我画font。在屏幕上,我可以看到ASCII和西里尔字符。然而,我无法使DrawTextEx呈现这些字符,但DrawTextCodepointworks as I expected it to。例如:

    BeginDrawing();
    ClearBackground(RAYWHITE);

    DrawTextEx(font, "Ё", (Vector2) { 10, 70 }, 32, 0, BLACK); // draws a ? symbol
    DrawTextEx(font, "\u0401", (Vector2) { 10, 40 }, 32, 0, BLACK); // draws a ? symbol
    DrawTextCodepoint(font, 0x0401, (Vector2) { 10, 10 }, 32, BLACK); // draws Ё, as expected       
    EndDrawing();

共1个答案

匿名用户

我应该多花几分钟时间搜索一下答案。我使用的是Visual Studio 2022,在查看了一个更一般的问题的响应后,我突然意识到我应该显式地将我的字符串标记为用< code>u8前缀编码的UTF-8。因此,这将完美地工作:

DrawTextEx(font, u8"Ё", (Vector2) { 10, 70 }, 32, 0, BLACK); // draws Ё, as expected    
DrawTextEx(font, u8"\u0401", (Vector2) { 10, 40 }, 32, 0, BLACK); // draws Ё, as expected too