text_bmfont_ttf.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [text] example - BMFont and TTF SpriteFonts loading
  4. --
  5. -- This example has been created using raylib 1.6 (www.raylib.com)
  6. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. --
  8. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  9. --
  10. -------------------------------------------------------------------------------------------
  11. -- Initialization
  12. -------------------------------------------------------------------------------------------
  13. local screenWidth = 800
  14. local screenHeight = 450
  15. InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading")
  16. local msgBm = "THIS IS AN AngelCode SPRITE FONT"
  17. local msgTtf = "THIS FONT has been GENERATED from TTF"
  18. -- NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  19. local fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt") -- BMFont (AngelCode)
  20. local fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf") -- TTF font
  21. local fontPosition = Vector2(0, 0)
  22. fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2
  23. fontPosition.y = screenHeight/2 - fontBm.size/2 - 80
  24. SetTargetFPS(60) -- Set target frames-per-second
  25. -------------------------------------------------------------------------------------------
  26. -- Main game loop
  27. while not WindowShouldClose() do -- Detect window close button or ESC key
  28. -- Update
  29. ---------------------------------------------------------------------------------------
  30. -- TODO: Update variables here...
  31. ---------------------------------------------------------------------------------------
  32. -- Draw
  33. ---------------------------------------------------------------------------------------
  34. BeginDrawing()
  35. ClearBackground(RAYWHITE)
  36. DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON)
  37. DrawTextEx(fontTtf, msgTtf, Vector2(60.0, 240.0), fontTtf.size, 2, LIME)
  38. EndDrawing()
  39. ---------------------------------------------------------------------------------------
  40. end
  41. -- De-Initialization
  42. -------------------------------------------------------------------------------------------
  43. UnloadSpriteFont(fontBm) -- AngelCode SpriteFont unloading
  44. UnloadSpriteFont(fontTtf) -- TTF SpriteFont unloading
  45. CloseWindow() -- Close window and OpenGL context
  46. -------------------------------------------------------------------------------------------