You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.4 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - BMFont and TTF Fonts loading
  4. *
  5. * This example has been created using raylib 1.4 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2016 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. const int screenWidth = 800;
  17. const int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");
  19. // Define characters to draw
  20. // NOTE: raylib supports UTF-8 encoding, following list is actually codified as UTF8 internally
  21. const char msg[256] = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI\nJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmn\nopqrstuvwxyz{|}~¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓ\nÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷\nøùúûüýþÿ";
  22. // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  23. // BMFont (AngelCode) : Font data and image atlas have been generated using external program
  24. Font fontBm = LoadFont("resources/pixantiqua.fnt");
  25. // TTF font : Font data and atlas are generated directly from TTF
  26. // NOTE: We define a font base size of 32 pixels tall and up-to 250 characters
  27. Font fontTtf = LoadFontEx("resources/pixantiqua.ttf", 32, 0, 250);
  28. bool useTtf = false;
  29. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. if (IsKeyDown(KEY_SPACE)) useTtf = true;
  37. else useTtf = false;
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY);
  44. if (!useTtf)
  45. {
  46. DrawTextEx(fontBm, msg, (Vector2){ 20.0f, 100.0f }, fontBm.baseSize, 2, MAROON);
  47. DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY);
  48. }
  49. else
  50. {
  51. DrawTextEx(fontTtf, msg, (Vector2){ 20.0f, 100.0f }, fontTtf.baseSize, 2, LIME);
  52. DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY);
  53. }
  54. EndDrawing();
  55. //----------------------------------------------------------------------------------
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. UnloadFont(fontBm); // AngelCode Font unloading
  60. UnloadFont(fontTtf); // TTF Font unloading
  61. CloseWindow(); // Close window and OpenGL context
  62. //--------------------------------------------------------------------------------------
  63. return 0;
  64. }