Advertisement
nezvers

Raylib custom font with UTF8

Jan 21st, 2022
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include "raylib.h"
  2.  
  3. #define TARGET_FPS 60
  4.  
  5. #define SCREEN_WIDTH 800
  6. #define SCREEN_HEIGHT 600
  7.  
  8. // https://en.cppreference.com/w/c/language/string_literal
  9. const unsigned char *example_text = u8"안녕하세요!";
  10.  
  11. int main(void) {
  12.     SetConfigFlags(FLAG_MSAA_4X_HINT);
  13.     SetTargetFPS(TARGET_FPS);
  14.    
  15.     InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "...");
  16.    
  17.     // The size of the font that we are going to load.
  18.     const int font_size = 32;
  19.  
  20.     // The number of the Unicode codepoints in `example_text`.
  21.     int codepoint_count = 0;
  22.  
  23.     // The Unicode codepoint array for `example_text`.
  24.     int *codepoints = LoadCodepoints(example_text, &codepoint_count);
  25.  
  26.     // Loads the TrueType font with the given codepoint array.
  27.     Font fnt_neodgm = LoadFontEx(
  28.         "../res/fonts/neodgm/neodgm.ttf",
  29.         font_size,
  30.         codepoints,
  31.         codepoint_count
  32.     );
  33.  
  34.     while (!WindowShouldClose()) {
  35.         BeginDrawing();
  36.        
  37.         ClearBackground(BLACK);
  38.  
  39.         // Draws the UTF-8 encoded text to the screen.
  40.         DrawTextEx(
  41.             fnt_neodgm,
  42.             example_text,
  43.             (Vector2) { 8.0f, 8.0f },
  44.             font_size,
  45.             2,
  46.             WHITE
  47.         );
  48.  
  49.         EndDrawing();
  50.     }
  51.  
  52.     // Unloads the font.
  53.     UnloadFont(fnt_neodgm);
  54.    
  55.     CloseWindow();
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement