|
| 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