Skip to content

Commit 1caab39

Browse files
Merge pull request #76 from sDos280/master
one more example added
2 parents c437d62 + d7eb090 commit 1caab39

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
3+
raylib [texture] example - To image
4+
5+
"""
6+
from pyray import *
7+
from raylib.colors import *
8+
9+
# Initialization
10+
screenWidth = 800
11+
screenHeight = 450
12+
13+
init_window(screenWidth, screenHeight, "raylib [textures] example - texture to image")
14+
15+
# NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
16+
17+
image = load_image("resources/raylib_logo.png") # Load image data into CPU memory (RAM)
18+
texture = load_texture_from_image(image) # Image converted to texture, GPU memory (RAM -> VRAM)
19+
unload_image(image) # Unload image data from CPU memory (RAM)
20+
21+
image = load_image_from_texture(texture) # Load image from GPU texture (VRAM -> RAM)
22+
unload_texture(texture) # Unload texture from GPU memory (VRAM)
23+
24+
texture = load_texture_from_image(image) # Recreate texture from retrieved image data (RAM -> VRAM)
25+
unload_image(image) # Unload retrieved image data from CPU memory (RAM)
26+
# ---------------------------------------------------------------------------------------
27+
28+
29+
# Main game loop
30+
while not window_should_close(): # Detect window close button or ESC key
31+
32+
# Update
33+
# ----------------------------------------------------------------------------------
34+
# TODO: Update your variables here
35+
# ----------------------------------------------------------------------------------
36+
37+
# Draw
38+
# ----------------------------------------------------------------------------------
39+
begin_drawing()
40+
41+
clear_background(RAYWHITE)
42+
43+
draw_texture(texture, int(screenWidth/2 - texture.width/2), int(screenHeight/2 - texture.height/2), WHITE)
44+
45+
draw_text("this IS a texture loaded from an image!", 300, 370, 10, GRAY)
46+
47+
end_drawing()
48+
# ----------------------------------------------------------------------------------
49+
50+
# De-Initialization
51+
# ----------------------------------------------------------------------------------
52+
unload_texture(texture) # Unload render texture
53+
54+
close_window() # Close window and OpenGL context

0 commit comments

Comments
 (0)