Skip to content

Commit

Permalink
Made defender example use glow/bloom
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Apr 8, 2020
1 parent cdf42c0 commit 9a99909
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions arcade/experimental/defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from arcade import shader
from arcade.experimental import geometry

# --- Bloom related ---
from arcade.experimental import postprocessing
import pyglet.gl as gl

SPRITE_SCALING = 0.5

SCREEN_WIDTH = 800
Expand Down Expand Up @@ -123,16 +127,21 @@ def __init__(self, width, height, title):
arcade.set_background_color(arcade.color.BLACK)

# --- Mini-map related ---
self.color_attachment = None
self.offscreen = None
self.minimap_color_attachment = None
self.minimap_screen = None
self.quad_fs = None
self.mini_map_quad = None

program = shader.load_program("simple_shader.vert", "simple_shader.frag")
self.color_attachment = shader.texture((SCREEN_WIDTH, SCREEN_HEIGHT), 4)
self.offscreen = shader.framebuffer(color_attachments=[self.color_attachment])
self.quad_fs = geometry.quad_fs(program, size=(2.0, 2.0))
self.minimap_color_attachment = shader.texture((SCREEN_WIDTH, SCREEN_HEIGHT), 4)
self.minimap_screen = shader.framebuffer(color_attachments=[self.minimap_color_attachment])
self.play_screen_color_attachment = shader.texture((SCREEN_WIDTH, SCREEN_HEIGHT), 4)
self.play_screen = shader.framebuffer(color_attachments=[self.play_screen_color_attachment])
self.mini_map_quad = geometry.quad_fs(program, size=(2.0, 0.5), pos=(0.0, 0.75))
self.play_screen_quad = geometry.quad_fs(program, size=(2.0, 1.5), pos=(0.0, 0.0))

# --- Bloom related ---
self.glow = postprocessing.Glow((SCREEN_WIDTH // 8, SCREEN_HEIGHT // 8))

def setup(self):
""" Set up the game and initialize the variables. """
Expand Down Expand Up @@ -170,8 +179,8 @@ def on_draw(self):
arcade.start_render()

# Draw to the frame buffer used in the minimap
self.offscreen.use()
self.offscreen.clear()
self.minimap_screen.use()
self.minimap_screen.clear()

arcade.set_viewport(0,
PLAYING_FIELD_WIDTH,
Expand All @@ -183,7 +192,10 @@ def on_draw(self):
self.player_list.draw()

# Now draw to the actual screen
self.use()
self.play_screen.use()
self.play_screen.clear()

# self.use()

arcade.set_viewport(self.view_left,
SCREEN_WIDTH + self.view_left,
Expand All @@ -199,6 +211,17 @@ def on_draw(self):
# Draw the ground
arcade.draw_line(0, 0, PLAYING_FIELD_WIDTH, 0, arcade.color.WHITE)

self.use()

arcade.set_viewport(self.view_left,
SCREEN_WIDTH + self.view_left,
self.view_bottom,
SCREEN_HEIGHT + self.view_bottom)

gl.glDisable(gl.GL_BLEND)
self.glow.render(self.play_screen_color_attachment, self)
gl.glEnable(gl.GL_BLEND)

# Draw a background for the minimap
arcade.draw_rectangle_filled(SCREEN_WIDTH - SCREEN_WIDTH / 2 + self.view_left,
SCREEN_HEIGHT - SCREEN_HEIGHT / 8 + self.view_bottom,
Expand All @@ -207,7 +230,7 @@ def on_draw(self):
arcade.color.DARK_GREEN)

# Draw the minimap
self.color_attachment.use(0)
self.minimap_color_attachment.use(0)
self.mini_map_quad.render()

# Draw a rectangle showing where the screen is
Expand All @@ -222,6 +245,8 @@ def on_draw(self):
width=width, height=height,
color=arcade.color.WHITE)

print("Done")

def on_update(self, delta_time):
""" Movement and game logic """

Expand Down

0 comments on commit 9a99909

Please sign in to comment.