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.

84 lines
3.7 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - Sprite font loading
  4. *
  5. * Loaded sprite fonts have been generated following XNA SpriteFont conventions:
  6. * - Characters must be ordered starting with character 32 (Space)
  7. * - Every character must be contained within the same Rectangle height
  8. * - Every character and every line must be separated the same distance
  9. * - Rectangles must be defined by a MAGENTA color background
  10. *
  11. * If following this constraints, a font can be provided just by an image,
  12. * this is quite handy to avoid additional information files (like BMFonts use).
  13. *
  14. * This example has been created using raylib 1.0 (www.raylib.com)
  15. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  16. *
  17. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  18. *
  19. ********************************************************************************************/
  20. #include "raylib.h"
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite font loading");
  28. const char msg1[50] = "THIS IS A custom SPRITE FONT...";
  29. const char msg2[50] = "...and this is ANOTHER CUSTOM font...";
  30. const char msg3[50] = "...and a THIRD one! GREAT! :D";
  31. // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  32. Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
  33. Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
  34. Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
  35. Vector2 fontPosition1 = { screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2,
  36. screenHeight/2 - font1.baseSize/2 - 80 };
  37. Vector2 fontPosition2 = { screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2,
  38. screenHeight/2 - font2.baseSize/2 - 10 };
  39. Vector2 fontPosition3 = { screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2,
  40. screenHeight/2 - font3.baseSize/2 + 50 };
  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. // Update
  47. //----------------------------------------------------------------------------------
  48. // TODO: Update variables here...
  49. //----------------------------------------------------------------------------------
  50. // Draw
  51. //----------------------------------------------------------------------------------
  52. BeginDrawing();
  53. ClearBackground(RAYWHITE);
  54. DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE);
  55. DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE);
  56. DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE);
  57. EndDrawing();
  58. //----------------------------------------------------------------------------------
  59. }
  60. // De-Initialization
  61. //--------------------------------------------------------------------------------------
  62. UnloadFont(font1); // Font unloading
  63. UnloadFont(font2); // Font unloading
  64. UnloadFont(font3); // Font unloading
  65. CloseWindow(); // Close window and OpenGL context
  66. //--------------------------------------------------------------------------------------
  67. return 0;
  68. }