From ba61381d243ec04ee8c7844ffac640f7eb2e4f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D7=93=D7=95=D7=A8=20=D7=A9=D7=A4=D7=99=D7=A8=D7=90?= Date: Sun, 31 Jul 2022 15:37:37 +0300 Subject: [PATCH] adding the textures_to_image example --- examples/textures/textures_to_image.py | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/textures/textures_to_image.py diff --git a/examples/textures/textures_to_image.py b/examples/textures/textures_to_image.py new file mode 100644 index 0000000..96c50a4 --- /dev/null +++ b/examples/textures/textures_to_image.py @@ -0,0 +1,54 @@ +""" + +raylib [texture] example - To image + +""" +from pyray import * +from raylib.colors import * + +# Initialization +screenWidth = 800 +screenHeight = 450 + +init_window(screenWidth, screenHeight, "raylib [textures] example - texture to image") + +# NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + +image = load_image("resources/raylib_logo.png") # Load image data into CPU memory (RAM) +texture = load_texture_from_image(image) # Image converted to texture, GPU memory (RAM -> VRAM) +unload_image(image) # Unload image data from CPU memory (RAM) + +image = load_image_from_texture(texture) # Load image from GPU texture (VRAM -> RAM) +unload_texture(texture) # Unload texture from GPU memory (VRAM) + +texture = load_texture_from_image(image) # Recreate texture from retrieved image data (RAM -> VRAM) +unload_image(image) # Unload retrieved image data from CPU memory (RAM) +# --------------------------------------------------------------------------------------- + + +# Main game loop +while not window_should_close(): # Detect window close button or ESC key + + # Update + # ---------------------------------------------------------------------------------- + # TODO: Update your variables here + # ---------------------------------------------------------------------------------- + + # Draw + # ---------------------------------------------------------------------------------- + begin_drawing() + + clear_background(RAYWHITE) + + draw_texture(texture, int(screenWidth/2 - texture.width/2), int(screenHeight/2 - texture.height/2), WHITE) + + draw_text("this IS a texture loaded from an image!", 300, 370, 10, GRAY) + + end_drawing() + # ---------------------------------------------------------------------------------- + +# De-Initialization +# ---------------------------------------------------------------------------------- +unload_texture(texture) # Unload render texture + +close_window() # Close window and OpenGL context