Last active
November 14, 2021 00:27
-
-
Save dannyow/d5f8557bd245afe7d788b8d7a75a1643 to your computer and use it in GitHub Desktop.
How to print a non-latin text with raylib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <raylib.h> | |
int main(void) { | |
const int screenWidth = 800; | |
const int screenHeight = 450; | |
SetConfigFlags(FLAG_VSYNC_HINT); | |
SetConfigFlags(FLAG_WINDOW_RESIZABLE); | |
SetConfigFlags(FLAG_WINDOW_HIGHDPI); | |
const char *text = "zażółć gęślą jaźń"; | |
int codePointCnt = 0; | |
int *codePoints = LoadCodepoints(text, &codePointCnt); | |
InitWindow(screenWidth, screenHeight, "raylib unicode"); | |
Font font = LoadFontEx("resources/JetBrainsMono-Regular.ttf", 64, codePoints, codePointCnt); | |
SetTargetFPS(60); | |
while (!WindowShouldClose()) { | |
if (IsKeyPressed(KEY_ONE)) { | |
SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); | |
} else if (IsKeyPressed(KEY_TWO)) { | |
SetTextureFilter(font.texture, TEXTURE_FILTER_BILINEAR); | |
} else if (IsKeyPressed(KEY_THREE)) { | |
// NOTE: Trilinear filter won't be noticed on 2D drawing | |
SetTextureFilter(font.texture, TEXTURE_FILTER_TRILINEAR); | |
} | |
BeginDrawing(); | |
ClearBackground(RAYWHITE); | |
DrawText("zażółć gęślą jaźń", 190, 200, 20, LIGHTGRAY); | |
DrawCircle(screenWidth / 5, 120, 35, DARKBLUE); | |
DrawCircleLines(screenWidth / 5, 340, 80, DARKBLUE); | |
DrawTextEx(font, text, (Vector2){20.0f, 100.0f}, (float)font.baseSize / 2, 2, LIME); | |
EndDrawing(); | |
} | |
UnloadCodepoints(codePoints); | |
UnloadFont(font); | |
CloseWindow(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment