From 2f5eb6ab368b062dbbde39b3cee6eae23c5452ff Mon Sep 17 00:00:00 2001 From: Amir Rajan Date: Mon, 6 Sep 2021 14:32:04 -0500 Subject: Synced with version 2.26 --- .../11_render_target_noclear/app/main.rb | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 samples/07_advanced_rendering/11_render_target_noclear/app/main.rb (limited to 'samples/07_advanced_rendering/11_render_target_noclear/app/main.rb') diff --git a/samples/07_advanced_rendering/11_render_target_noclear/app/main.rb b/samples/07_advanced_rendering/11_render_target_noclear/app/main.rb new file mode 100644 index 0000000..9e5dffd --- /dev/null +++ b/samples/07_advanced_rendering/11_render_target_noclear/app/main.rb @@ -0,0 +1,47 @@ +def tick args + args.state.x ||= 500 + args.state.y ||= 350 + args.state.xinc ||= 7 + args.state.yinc ||= 7 + args.state.bgcolor ||= 1 + args.state.bginc ||= 1 + + # clear the render target on the first tick, and then never again. Draw + # another box to it every tick, accumulating over time. + clear_target = (args.state.tick_count == 0) || (args.inputs.keyboard.key_down.space) + args.render_target(:accumulation).background_color = [ 0, 0, 0, 0 ]; + args.render_target(:accumulation).clear_before_render = clear_target + args.render_target(:accumulation).solids << [args.state.x, args.state.y, 25, 25, 255, 0, 0, 255]; + args.state.x += args.state.xinc + args.state.y += args.state.yinc + args.state.bgcolor += args.state.bginc + + # animation upkeep...change where we draw the next box and what color the + # window background will be. + if args.state.xinc > 0 && args.state.x >= 1280 + args.state.xinc = -7 + elsif args.state.xinc < 0 && args.state.x < 0 + args.state.xinc = 7 + end + + if args.state.yinc > 0 && args.state.y >= 720 + args.state.yinc = -7 + elsif args.state.yinc < 0 && args.state.y < 0 + args.state.yinc = 7 + end + + if args.state.bginc > 0 && args.state.bgcolor >= 255 + args.state.bginc = -1 + elsif args.state.bginc < 0 && args.state.bgcolor <= 0 + args.state.bginc = 1 + end + + # clear the screen to a shade of blue and draw the render target, which + # is not clearing every frame, on top of it. Note that you can NOT opt to + # skip clearing the screen, only render targets. The screen clears every + # frame; double-buffering would prevent correct updates between frames. + args.outputs.background_color = [ 0, 0, args.state.bgcolor, 255 ] + args.outputs.sprites << [ 0, 0, 1280, 720, :accumulation ] +end + +$gtk.reset -- cgit v1.2.3