I'm trying to display a string, which contains Cyrillic characters using raylib. So I load a font with codepoints like so:
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);
If I draw font.texture
on screen, I can see both ASCII and Cyrillic characters on screen. However, I can't make DrawTextEx
render those characters, yet DrawTextCodepoint
works as I expect it to. For example:
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();
I should have spent just a few more minutes googling for an answer. I'm using Visual Studio 2022, and after looking at this response for a more general question, it dawned on me that I should explicitly mark my string literals as UTF-8 encoded with the u8
prefix. So, this will work perfectly:
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