text_bmfont_unordered.c 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - BMFont unordered chars loading and drawing
  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. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. const int screenWidth = 800;
  19. const int screenHeight = 450;
  20. // NOTE: Using chars outside the [32..127] limits!
  21. // NOTE: If a character is not found in the font, it just renders a space
  22. const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
  23. SpriteFont font;
  24. //----------------------------------------------------------------------------------
  25. // Module Functions Declaration
  26. //----------------------------------------------------------------------------------
  27. void UpdateDrawFrame(void); // Update and Draw one frame
  28. //----------------------------------------------------------------------------------
  29. // Main Enry Point
  30. //----------------------------------------------------------------------------------
  31. int main()
  32. {
  33. // Initialization
  34. //--------------------------------------------------------------------------------------
  35. InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing");
  36. // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
  37. font = LoadSpriteFont("resources/pixantiqua.fnt"); // BMFont (AngelCode)
  38. #if defined(PLATFORM_WEB)
  39. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  40. #else
  41. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  42. //--------------------------------------------------------------------------------------
  43. // Main game loop
  44. while (!WindowShouldClose()) // Detect window close button or ESC key
  45. {
  46. UpdateDrawFrame();
  47. }
  48. #endif
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. UnloadSpriteFont(font); // Unload music stream buffers from RAM
  52. CloseWindow(); // Close window and OpenGL context
  53. //--------------------------------------------------------------------------------------
  54. return 0;
  55. }
  56. //----------------------------------------------------------------------------------
  57. // Module Functions Definition
  58. //----------------------------------------------------------------------------------
  59. void UpdateDrawFrame(void)
  60. {
  61. // Update
  62. //----------------------------------------------------------------------------------
  63. // TODO: Update variables here...
  64. //----------------------------------------------------------------------------------
  65. // Draw
  66. //----------------------------------------------------------------------------------
  67. BeginDrawing();
  68. ClearBackground(RAYWHITE);
  69. DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY);
  70. DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY);
  71. DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY);
  72. DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.baseSize, 0, MAROON);
  73. EndDrawing();
  74. //----------------------------------------------------------------------------------
  75. }