--- /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/latest/doc/tutorials/raycasting/start.py
+++ /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/latest/doc/tutorials/raycasting/step_01.py
@@ -1,5 +1,8 @@
import random
+from pathlib import Path
+
import arcade
+from arcade.experimental import Shadertoy
# Do the math to figure out our screen dimensions
SCREEN_WIDTH = 800
@@ -20,7 +23,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 +40,29 @@
self.generate_sprites()
arcade.set_background_color(arcade.color.ARMY_GREEN)
+
+ def load_shader(self):
+ # Where is the shader file? Must be specified as a path.
+ shader_file_path = Path("step_01.glsl")
+
+ # Size of the window
+ window_size = self.get_size()
+
+ # Create the shader toy
+ self.shadertoy = Shadertoy.create_from_file(window_size, shader_file_path)
+
+ # 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 +97,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. """