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.

67 lines
2.7 KiB

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