adding the textures_to_image example
This commit is contained in:
parent
ad21fe7b8e
commit
ba61381d24
1 changed files with 54 additions and 0 deletions
54
examples/textures/textures_to_image.py
Normal file
54
examples/textures/textures_to_image.py
Normal file
|
@ -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
|
Reference in a new issue