textures_svg_loading.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - SVG loading and texture creation
  4. *
  5. * NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
  6. *
  7. * Example originally created with raylib 4.2, last time updated with raylib 4.2
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2022 Dennis Meinen (@bixxy#4258 on Discord)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [textures] example - svg loading");
  26. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  27. Image image = LoadImageSvg("resources/test.svg", 400, 350); // Loaded in CPU memory (RAM)
  28. Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
  29. UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //---------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. // TODO: Update your variables here
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
  44. //Red border to illustrate how the SVG is centered within the specified dimensions
  45. DrawRectangleLines((screenWidth / 2 - texture.width / 2) - 1, (screenHeight / 2 - texture.height / 2) - 1, texture.width + 2, texture.height + 2, RED);
  46. DrawText("this IS a texture loaded from an SVG file!", 300, 410, 10, GRAY);
  47. EndDrawing();
  48. //----------------------------------------------------------------------------------
  49. }
  50. // De-Initialization
  51. //--------------------------------------------------------------------------------------
  52. UnloadTexture(texture); // Texture unloading
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }