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.

96 lines
4.2 KiB

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