Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

90 rindas
4.1 KiB

pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 mēnešiem
pirms 11 gadiem
pirms 5 gadiem
pirms 11 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - Sprite font loading
  4. *
  5. * NOTE: Sprite fonts should be generated following this conventions:
  6. *
  7. * - Characters must be ordered starting with character 32 (Space)
  8. * - Every character must be contained within the same Rectangle height
  9. * - Every character and every line must be separated by the same distance (margin/padding)
  10. * - Rectangles must be defined by a MAGENTA color background
  11. *
  12. * Following those constraints, a font can be provided just by an image,
  13. * this is quite handy to avoid additional font descriptor files (like BMFonts use).
  14. *
  15. * Example originally created with raylib 1.0, last time updated with raylib 1.0
  16. *
  17. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  18. * BSD-like license that allows static linking with closed source software
  19. *
  20. * Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
  21. *
  22. ********************************************************************************************/
  23. #include "raylib.h"
  24. //------------------------------------------------------------------------------------
  25. // Program main entry point
  26. //------------------------------------------------------------------------------------
  27. int main(void)
  28. {
  29. // Initialization
  30. //--------------------------------------------------------------------------------------
  31. const int screenWidth = 800;
  32. const int screenHeight = 450;
  33. InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite font loading");
  34. const char msg1[50] = "THIS IS A custom SPRITE FONT...";
  35. const char msg2[50] = "...and this is ANOTHER CUSTOM font...";
  36. const char msg3[50] = "...and a THIRD one! GREAT! :D";
  37. // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  38. Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
  39. Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
  40. Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
  41. Vector2 fontPosition1 = { screenWidth/2.0f - MeasureTextEx(font1, msg1, (float)font1.baseSize, -3).x/2,
  42. screenHeight/2.0f - font1.baseSize/2.0f - 80.0f };
  43. Vector2 fontPosition2 = { screenWidth/2.0f - MeasureTextEx(font2, msg2, (float)font2.baseSize, -2.0f).x/2.0f,
  44. screenHeight/2.0f - font2.baseSize/2.0f - 10.0f };
  45. Vector2 fontPosition3 = { screenWidth/2.0f - MeasureTextEx(font3, msg3, (float)font3.baseSize, 2.0f).x/2.0f,
  46. screenHeight/2.0f - font3.baseSize/2.0f + 50.0f };
  47. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  48. //--------------------------------------------------------------------------------------
  49. // Main game loop
  50. while (!WindowShouldClose()) // Detect window close button or ESC key
  51. {
  52. // Update
  53. //----------------------------------------------------------------------------------
  54. // TODO: Update variables here...
  55. //----------------------------------------------------------------------------------
  56. // Draw
  57. //----------------------------------------------------------------------------------
  58. BeginDrawing();
  59. ClearBackground(RAYWHITE);
  60. DrawTextEx(font1, msg1, fontPosition1, (float)font1.baseSize, -3, WHITE);
  61. DrawTextEx(font2, msg2, fontPosition2, (float)font2.baseSize, -2, WHITE);
  62. DrawTextEx(font3, msg3, fontPosition3, (float)font3.baseSize, 2, WHITE);
  63. EndDrawing();
  64. //----------------------------------------------------------------------------------
  65. }
  66. // De-Initialization
  67. //--------------------------------------------------------------------------------------
  68. UnloadFont(font1); // Font unloading
  69. UnloadFont(font2); // Font unloading
  70. UnloadFont(font3); // Font unloading
  71. CloseWindow(); // Close window and OpenGL context
  72. //--------------------------------------------------------------------------------------
  73. return 0;
  74. }