|
| 1 | +""" |
| 2 | +
|
| 3 | +raylib [core] example - Scissor Test |
| 4 | +
|
| 5 | +""" |
| 6 | +from pyray import * |
| 7 | +from raylib.colors import ( |
| 8 | + RAYWHITE, |
| 9 | + LIGHTGRAY, |
| 10 | + RED, |
| 11 | + BLACK |
| 12 | +) |
| 13 | +from raylib import ( |
| 14 | + KEY_S |
| 15 | +) |
| 16 | + |
| 17 | +# Initialization |
| 18 | +# -------------------------------------------------------------------------------------- |
| 19 | +SCREEN_WIDTH = 800 |
| 20 | +SCREEN_HEIGHT = 450 |
| 21 | + |
| 22 | +init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - scissor test") |
| 23 | + |
| 24 | +scissorArea = Rectangle(0, 0, 300, 300) |
| 25 | +scissorMode = True |
| 26 | + |
| 27 | +set_target_fps(60) # Set our game to run at 60 frames-per-second |
| 28 | +# -------------------------------------------------------------------------------------- |
| 29 | + |
| 30 | +# Main game loop |
| 31 | +while not window_should_close(): # Detect window close button or ESC key |
| 32 | + # Update |
| 33 | + # ---------------------------------------------------------------------------------- |
| 34 | + if is_key_pressed(KEY_S): |
| 35 | + scissorMode = not scissorMode |
| 36 | + |
| 37 | + # Centre the scissor area around the mouse position |
| 38 | + scissorArea.x = get_mouse_x() - scissorArea.width/2 |
| 39 | + scissorArea.y = get_mouse_y() - scissorArea.height/2 |
| 40 | + # ---------------------------------------------------------------------------------- |
| 41 | + |
| 42 | + |
| 43 | + # Draw |
| 44 | + # ---------------------------------------------------------------------------------- |
| 45 | + begin_drawing() |
| 46 | + |
| 47 | + clear_background(RAYWHITE) |
| 48 | + if scissorMode: |
| 49 | + begin_scissor_mode(int(scissorArea.x), int(scissorArea.y), int(scissorArea.width), int(scissorArea.height)) |
| 50 | + |
| 51 | + # Draw full screen rectangle and some text |
| 52 | + # NOTE: Only part defined by scissor area will be rendered |
| 53 | + draw_rectangle(0, 0, get_screen_width(), get_screen_height(), RED) |
| 54 | + draw_text("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY) |
| 55 | + |
| 56 | + if scissorMode: |
| 57 | + end_scissor_mode() |
| 58 | + |
| 59 | + draw_rectangle_lines_ex(scissorArea, 1, BLACK) |
| 60 | + draw_text("Press S to toggle scissor test", 10, 10, 20, BLACK) |
| 61 | + |
| 62 | + end_drawing() |
| 63 | + |
| 64 | +# De-Initialization |
| 65 | +close_window() # Close window and OpenGL context |
0 commit comments