25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - raylib font loading and usage
  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. * This example has been created using raylib 1.7 (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2017 Ramon Santamaria (@raysan5)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. #define MAX_FONTS 8
  16. int main(void)
  17. {
  18. // Initialization
  19. //--------------------------------------------------------------------------------------
  20. const int screenWidth = 800;
  21. const int screenHeight = 450;
  22. InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
  23. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  24. Font fonts[MAX_FONTS] = { 0 };
  25. fonts[0] = LoadFont("resources/fonts/alagard.png");
  26. fonts[1] = LoadFont("resources/fonts/pixelplay.png");
  27. fonts[2] = LoadFont("resources/fonts/mecha.png");
  28. fonts[3] = LoadFont("resources/fonts/setback.png");
  29. fonts[4] = LoadFont("resources/fonts/romulus.png");
  30. fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
  31. fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
  32. fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");
  33. const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
  34. "PIXELPLAY FONT designed by Aleksander Shevchuk",
  35. "MECHA FONT designed by Captain Falcon",
  36. "SETBACK FONT designed by Brian Kent (AEnigma)",
  37. "ROMULUS FONT designed by Hewett Tsoi",
  38. "PIXANTIQUA FONT designed by Gerhard Grossmann",
  39. "ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
  40. "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
  41. const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 };
  42. Vector2 positions[MAX_FONTS] = { 0 };
  43. for (int i = 0; i < MAX_FONTS; i++)
  44. {
  45. positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2;
  46. positions[i].y = 60 + fonts[i].baseSize + 45*i;
  47. }
  48. // Small Y position corrections
  49. positions[3].y += 8;
  50. positions[4].y += 2;
  51. positions[7].y -= 8;
  52. Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED };
  53. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  54. //--------------------------------------------------------------------------------------
  55. // Main game loop
  56. while (!WindowShouldClose()) // Detect window close button or ESC key
  57. {
  58. // Update
  59. //----------------------------------------------------------------------------------
  60. // TODO: Update your variables here
  61. //----------------------------------------------------------------------------------
  62. // Draw
  63. //----------------------------------------------------------------------------------
  64. BeginDrawing();
  65. ClearBackground(RAYWHITE);
  66. DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
  67. DrawLine(220, 50, 590, 50, DARKGRAY);
  68. for (int i = 0; i < MAX_FONTS; i++)
  69. {
  70. DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]);
  71. }
  72. EndDrawing();
  73. //----------------------------------------------------------------------------------
  74. }
  75. // De-Initialization
  76. //--------------------------------------------------------------------------------------
  77. // Fonts unloading
  78. for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
  79. CloseWindow(); // Close window and OpenGL context
  80. //--------------------------------------------------------------------------------------
  81. return 0;
  82. }