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.

86 lines
3.9 KiB

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