Step_01.py差异#
Start.py到Step_01.py的差异#
--- /pb1/repo/arcade/doc/tutorials/raycasting/start.py
+++ /pb1/repo/arcade/doc/tutorials/raycasting/step_01.py
@@ -1,5 +1,7 @@
import random
+
import arcade
+from arcade.experimental import Shadertoy
# Do the math to figure out our screen dimensions
SCREEN_WIDTH = 800
@@ -20,7 +22,13 @@
class MyGame(arcade.Window):
def __init__(self, width, height, title):
- super().__init__(width, height, title, resizable=True)
+ super().__init__(width, height, title)
+
+ # The shader toy and 'channels' we'll be using
+ self.shadertoy = None
+ self.channel0 = None
+ self.channel1 = None
+ self.load_shader()
# Sprites and sprite lists
self.player_sprite = None
@@ -31,6 +39,26 @@
self.generate_sprites()
self.background_color = arcade.color.ARMY_GREEN
+
+ def load_shader(self):
+ # Size of the window
+ window_size = self.get_size()
+
+ # Create the shader toy, passing in a path for the shader source
+ self.shadertoy = Shadertoy.create_from_file(window_size, "step_01.glsl")
+
+ # Create the channels 0 and 1 frame buffers.
+ # Make the buffer the size of the window, with 4 channels (RGBA)
+ self.channel0 = self.shadertoy.ctx.framebuffer(
+ color_attachments=[self.shadertoy.ctx.texture(window_size, components=4)]
+ )
+ self.channel1 = self.shadertoy.ctx.framebuffer(
+ color_attachments=[self.shadertoy.ctx.texture(window_size, components=4)]
+ )
+
+ # Assign the frame buffers to the channels
+ self.shadertoy.channel_0 = self.channel0.color_attachments[0]
+ self.shadertoy.channel_1 = self.channel1.color_attachments[0]
def generate_sprites(self):
# -- Set up several columns of walls
@@ -65,11 +93,18 @@
self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list)
def on_draw(self):
+ # Select the channel 0 frame buffer to draw on
+ self.channel0.use()
+ self.channel0.clear()
+ # Draw the walls
+ self.wall_list.draw()
+
+ # Select this window to draw on
+ self.use()
+ # Clear to background color
self.clear()
-
- self.wall_list.draw()
- self.bomb_list.draw()
- self.player_list.draw()
+ # Run the shader and render to the window
+ self.shadertoy.render()
def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed. """