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.

76 regels
3.5 KiB

11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
  1. /*******************************************************************************************
  2. *
  3. * raylib example 05a - SpriteFont loading and drawing some text with it
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. const char msg1[50] = "THIS IS A custom SPRITE FONT...";
  19. const char msg2[50] = "...and this is ANOTHER CUSTOM font...";
  20. const char msg3[50] = "...and a THIRD one! GREAT! :D";
  21. InitWindow(screenWidth, screenHeight, "raylib example 05a - sprite fonts");
  22. // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  23. SpriteFont font1 = LoadSpriteFont("resources/fonts/custom_mecha.png"); // SpriteFont loading
  24. SpriteFont font2 = LoadSpriteFont("resources/fonts/custom_alagard.png"); // SpriteFont loading
  25. SpriteFont font3 = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png"); // SpriteFont loading
  26. Vector2 fontPosition1, fontPosition2, fontPosition3;
  27. fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, GetFontBaseSize(font1), -3).x/2;
  28. fontPosition1.y = screenHeight/2 - GetFontBaseSize(font1)/2 - 80;
  29. fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, GetFontBaseSize(font2), -2).x/2;
  30. fontPosition2.y = screenHeight/2 - GetFontBaseSize(font2)/2 - 10;
  31. fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, GetFontBaseSize(font3), 2).x/2;
  32. fontPosition3.y = screenHeight/2 - GetFontBaseSize(font3)/2 + 50;
  33. //--------------------------------------------------------------------------------------
  34. // Main game loop
  35. while (!WindowShouldClose()) // Detect window close button or ESC key
  36. {
  37. // Update
  38. //----------------------------------------------------------------------------------
  39. // TODO: Update variables here...
  40. //----------------------------------------------------------------------------------
  41. // Draw
  42. //----------------------------------------------------------------------------------
  43. BeginDrawing();
  44. ClearBackground(RAYWHITE);
  45. DrawTextEx(font1, msg1, fontPosition1, GetFontBaseSize(font1), -3, WHITE);
  46. DrawTextEx(font2, msg2, fontPosition2, GetFontBaseSize(font2), -2, WHITE);
  47. DrawTextEx(font3, msg3, fontPosition3, GetFontBaseSize(font3), 2, WHITE);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. UnloadSpriteFont(font1); // SpriteFont unloading
  54. UnloadSpriteFont(font2); // SpriteFont unloading
  55. UnloadSpriteFont(font3); // SpriteFont unloading
  56. CloseWindow(); // Close window and OpenGL context
  57. //--------------------------------------------------------------------------------------
  58. return 0;
  59. }