25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

109 satır
4.5 KiB

11 yıl önce
9 yıl önce
9 yıl önce
9 yıl önce
9 yıl önce
9 yıl önce
9 yıl önce
9 yıl önce
  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - raylib fonts loading
  4. *
  5. * NOTE: raylib is distributed with some free to use fonts (even for commercial pourposes!)
  6. * To view details and credits for those fonts, check raylib license file
  7. *
  8. * Example originally created with raylib 1.7, last time updated with raylib 3.7
  9. *
  10. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  11. * BSD-like license that allows static linking with closed source software
  12. *
  13. * Copyright (c) 2017-2024 Ramon Santamaria (@raysan5)
  14. *
  15. ********************************************************************************************/
  16. #include "raylib.h"
  17. #define MAX_FONTS 8
  18. //------------------------------------------------------------------------------------
  19. // Program main entry point
  20. //------------------------------------------------------------------------------------
  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 - raylib fonts");
  28. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  29. Font fonts[MAX_FONTS] = { 0 };
  30. fonts[0] = LoadFont("resources/fonts/alagard.png");
  31. fonts[1] = LoadFont("resources/fonts/pixelplay.png");
  32. fonts[2] = LoadFont("resources/fonts/mecha.png");
  33. fonts[3] = LoadFont("resources/fonts/setback.png");
  34. fonts[4] = LoadFont("resources/fonts/romulus.png");
  35. fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
  36. fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
  37. fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");
  38. const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
  39. "PIXELPLAY FONT designed by Aleksander Shevchuk",
  40. "MECHA FONT designed by Captain Falcon",
  41. "SETBACK FONT designed by Brian Kent (AEnigma)",
  42. "ROMULUS FONT designed by Hewett Tsoi",
  43. "PIXANTIQUA FONT designed by Gerhard Grossmann",
  44. "ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
  45. "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
  46. const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
  47. Vector2 positions[MAX_FONTS] = { 0 };
  48. for (int i = 0; i < MAX_FONTS; i++)
  49. {
  50. positions[i].x = screenWidth/2.0f - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2.0f, (float)spacings[i]).x/2.0f;
  51. positions[i].y = 60.0f + fonts[i].baseSize + 45.0f*i;
  52. }
  53. // Small Y position corrections
  54. positions[3].y += 8;
  55. positions[4].y += 2;
  56. positions[7].y -= 8;
  57. Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
  58. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  59. //--------------------------------------------------------------------------------------
  60. // Main game loop
  61. while (!WindowShouldClose()) // Detect window close button or ESC key
  62. {
  63. // Update
  64. //----------------------------------------------------------------------------------
  65. // TODO: Update your variables here
  66. //----------------------------------------------------------------------------------
  67. // Draw
  68. //----------------------------------------------------------------------------------
  69. BeginDrawing();
  70. ClearBackground(RAYWHITE);
  71. DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
  72. DrawLine(220, 50, 590, 50, DARKGRAY);
  73. for (int i = 0; i < MAX_FONTS; i++)
  74. {
  75. DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2.0f, (float)spacings[i], colors[i]);
  76. }
  77. EndDrawing();
  78. //----------------------------------------------------------------------------------
  79. }
  80. // De-Initialization
  81. //--------------------------------------------------------------------------------------
  82. // Fonts unloading
  83. for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
  84. CloseWindow(); // Close window and OpenGL context
  85. //--------------------------------------------------------------------------------------
  86. return 0;
  87. }