選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

76 行
3.4 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Retrieve image data from texture: LoadImageFromTexture()
  4. *
  5. * Example complexity rating: [] 1/4
  6. *
  7. * NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
  8. *
  9. * Example originally created with raylib 1.3, last time updated with raylib 4.0
  10. *
  11. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  12. * BSD-like license that allows static linking with closed source software
  13. *
  14. * Copyright (c) 2015-2025 Ramon Santamaria (@raysan5)
  15. *
  16. ********************************************************************************************/
  17. #include "raylib.h"
  18. //------------------------------------------------------------------------------------
  19. // Program main entry point
  20. //------------------------------------------------------------------------------------
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image");
  28. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  29. Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM)
  30. Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM)
  31. UnloadImage(image); // Unload image data from CPU memory (RAM)
  32. image = LoadImageFromTexture(texture); // Load image from GPU texture (VRAM -> RAM)
  33. UnloadTexture(texture); // Unload texture from GPU memory (VRAM)
  34. texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM)
  35. UnloadImage(image); // Unload retrieved image data from CPU memory (RAM)
  36. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  37. //---------------------------------------------------------------------------------------
  38. // Main game loop
  39. while (!WindowShouldClose()) // Detect window close button or ESC key
  40. {
  41. // Update
  42. //----------------------------------------------------------------------------------
  43. // TODO: Update your variables here
  44. //----------------------------------------------------------------------------------
  45. // Draw
  46. //----------------------------------------------------------------------------------
  47. BeginDrawing();
  48. ClearBackground(RAYWHITE);
  49. DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
  50. DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. UnloadTexture(texture); // Texture unloading
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }