| 22 | #include "raylib-cpp.hpp" |
| 23 | |
| 24 | int main() { |
| 25 | // Initialization |
| 26 | //-------------------------------------------------------------------------------------- |
| 27 | const int screenWidth = 800; |
| 28 | const int screenHeight = 450; |
| 29 | |
| 30 | raylib::Window window(screenWidth, screenHeight, "raylib [text] example - font loading"); |
| 31 | |
| 32 | // Define characters to draw |
| 33 | // NOTE: raylib supports UTF-8 encoding, following list is actually codified as UTF8 internally |
| 34 | std::string msg = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI\nJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmn\nopqrstuvwxyz{|}~¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓ\nÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷\nøùúûüýþÿ"; |
| 35 | |
| 36 | // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) |
| 37 | |
| 38 | // BMFont (AngelCode) : Font data and image atlas have been generated using external program |
| 39 | raylib::Font fontBm("resources/pixantiqua.fnt"); |
| 40 | |
| 41 | // TTF font : Font data and atlas are generated directly from TTF |
| 42 | // NOTE: We define a font base size of 32 pixels tall and up-to 250 characters |
| 43 | raylib::Font fontTtf("resources/pixantiqua.ttf", 32, 0, 250); |
| 44 | |
| 45 | bool useTtf = false; |
| 46 | |
| 47 | window.SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 48 | //-------------------------------------------------------------------------------------- |
| 49 | |
| 50 | // Main game loop |
| 51 | while (!window.ShouldClose()) { // Detect window close button or ESC key |
| 52 | // Update |
| 53 | //---------------------------------------------------------------------------------- |
| 54 | if (IsKeyDown(KEY_SPACE)) useTtf = true; |
| 55 | else useTtf = false; |
| 56 | //---------------------------------------------------------------------------------- |
| 57 | |
| 58 | // Draw |
| 59 | //---------------------------------------------------------------------------------- |
| 60 | window.BeginDrawing(); |
| 61 | { |
| 62 | |
| 63 | window.ClearBackground(RAYWHITE); |
| 64 | |
| 65 | raylib::DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY); |
| 66 | |
| 67 | if (!useTtf) |
| 68 | { |
| 69 | fontBm.DrawText(msg, Vector2{ 20.0f, 100.0f }, fontBm.baseSize, 2, MAROON); |
| 70 | raylib::DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY); |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | fontTtf.DrawText(msg, Vector2{ 20.0f, 100.0f }, fontTtf.baseSize, 2, LIME); |
| 75 | raylib::DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY); |
| 76 | } |
| 77 | } |
| 78 | window.EndDrawing(); |
| 79 | //---------------------------------------------------------------------------------- |
| 80 | } |
| 81 |
nothing calls this directly
no test coverage detected