Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

84 linhas
3.8 KiB

11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
11 anos atrás
  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - Sprite font loading
  4. *
  5. * Loaded sprite fonts have been generated following XNA SpriteFont conventions:
  6. * - Characters must be ordered starting with character 32 (Space)
  7. * - Every character must be contained within the same Rectangle height
  8. * - Every character and every line must be separated the same distance
  9. * - Rectangles must be defined by a MAGENTA color background
  10. *
  11. * If following this constraints, a font can be provided just by an image,
  12. * this is quite handy to avoid additional information files (like BMFonts use).
  13. *
  14. * This example has been created using raylib 1.0 (www.raylib.com)
  15. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  16. *
  17. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  18. *
  19. ********************************************************************************************/
  20. #include "raylib.h"
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite font loading");
  28. const char msg1[50] = "THIS IS A custom SPRITE FONT...";
  29. const char msg2[50] = "...and this is ANOTHER CUSTOM font...";
  30. const char msg3[50] = "...and a THIRD one! GREAT! :D";
  31. // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
  32. Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
  33. Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
  34. Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
  35. Vector2 fontPosition1 = { screenWidth/2.0f - MeasureTextEx(font1, msg1, (float)font1.baseSize, -3).x/2,
  36. screenHeight/2.0f - font1.baseSize/2.0f - 80.0f };
  37. Vector2 fontPosition2 = { screenWidth/2.0f - MeasureTextEx(font2, msg2, (float)font2.baseSize, -2.0f).x/2.0f,
  38. screenHeight/2.0f - font2.baseSize/2.0f - 10.0f };
  39. Vector2 fontPosition3 = { screenWidth/2.0f - MeasureTextEx(font3, msg3, (float)font3.baseSize, 2.0f).x/2.0f,
  40. screenHeight/2.0f - font3.baseSize/2.0f + 50.0f };
  41. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  42. //--------------------------------------------------------------------------------------
  43. // Main game loop
  44. while (!WindowShouldClose()) // Detect window close button or ESC key
  45. {
  46. // Update
  47. //----------------------------------------------------------------------------------
  48. // TODO: Update variables here...
  49. //----------------------------------------------------------------------------------
  50. // Draw
  51. //----------------------------------------------------------------------------------
  52. BeginDrawing();
  53. ClearBackground(RAYWHITE);
  54. DrawTextEx(font1, msg1, fontPosition1, (float)font1.baseSize, -3, WHITE);
  55. DrawTextEx(font2, msg2, fontPosition2, (float)font2.baseSize, -2, WHITE);
  56. DrawTextEx(font3, msg3, fontPosition3, (float)font3.baseSize, 2, WHITE);
  57. EndDrawing();
  58. //----------------------------------------------------------------------------------
  59. }
  60. // De-Initialization
  61. //--------------------------------------------------------------------------------------
  62. UnloadFont(font1); // Font unloading
  63. UnloadFont(font2); // Font unloading
  64. UnloadFont(font3); // Font unloading
  65. CloseWindow(); // Close window and OpenGL context
  66. //--------------------------------------------------------------------------------------
  67. return 0;
  68. }