1/*******************************************************************************************
2*
3* raylib [textures] example - Retrieve image data from texture: GetTextureData()
4*
5* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
6*
7* This example has been created using raylib 1.3 (www.raylib.com)
8* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
9*
10* Copyright (c) 2015 Ramon Santamaria (@raysan5)
11*
12********************************************************************************************/
13
14#include "raylib.h"
15
16int main(void)
17{
18 // Initialization
19 //--------------------------------------------------------------------------------------
20 const int screenWidth = 800;
21 const int screenHeight = 450;
22
23 InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image");
24
25 // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
26
27 Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM)
28 Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM)
29 UnloadImage(image); // Unload image data from CPU memory (RAM)
30
31 image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM)
32 UnloadTexture(texture); // Unload texture from GPU memory (VRAM)
33
34 texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM)
35 UnloadImage(image); // Unload retrieved image data from CPU memory (RAM)
36 //---------------------------------------------------------------------------------------
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
46 // Draw
47 //----------------------------------------------------------------------------------
48 BeginDrawing();
49
50 ClearBackground(RAYWHITE);
51
52 DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
53
54 DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);
55
56 EndDrawing();
57 //----------------------------------------------------------------------------------
58 }
59
60 // De-Initialization
61 //--------------------------------------------------------------------------------------
62 UnloadTexture(texture); // Texture unloading
63
64 CloseWindow(); // Close window and OpenGL context
65 //--------------------------------------------------------------------------------------
66
67 return 0;
68}