1 | /******************************************************************************************* |
2 | * |
3 | * raylib [textures] example - Image loading and texture creation |
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 | |
16 | int main(void) |
17 | { |
18 | // Initialization |
19 | //-------------------------------------------------------------------------------------- |
20 | const int screenWidth = 800; |
21 | const int screenHeight = 450; |
22 | |
23 | InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading" ); |
24 | |
25 | // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) |
26 | |
27 | Image image = LoadImage("resources/raylib_logo.png" ); // Loaded in CPU memory (RAM) |
28 | Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) |
29 | |
30 | UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM |
31 | //--------------------------------------------------------------------------------------- |
32 | |
33 | // Main game loop |
34 | while (!WindowShouldClose()) // Detect window close button or ESC key |
35 | { |
36 | // Update |
37 | //---------------------------------------------------------------------------------- |
38 | // TODO: Update your variables here |
39 | //---------------------------------------------------------------------------------- |
40 | |
41 | // Draw |
42 | //---------------------------------------------------------------------------------- |
43 | BeginDrawing(); |
44 | |
45 | ClearBackground(RAYWHITE); |
46 | |
47 | DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); |
48 | |
49 | DrawText("this IS a texture loaded from an image!" , 300, 370, 10, GRAY); |
50 | |
51 | EndDrawing(); |
52 | //---------------------------------------------------------------------------------- |
53 | } |
54 | |
55 | // De-Initialization |
56 | //-------------------------------------------------------------------------------------- |
57 | UnloadTexture(texture); // Texture unloading |
58 | |
59 | CloseWindow(); // Close window and OpenGL context |
60 | //-------------------------------------------------------------------------------------- |
61 | |
62 | return 0; |
63 | } |