From 4b1370fc286db564e32a8e2e890061bc3ed413ac Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 10 Feb 2016 22:00:02 -0500 Subject: examples: Update everything to use deferred GL resource loading. --- examples/shapes.scm | 56 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'examples/shapes.scm') diff --git a/examples/shapes.scm b/examples/shapes.scm index abaf371..1c20219 100644 --- a/examples/shapes.scm +++ b/examples/shapes.scm @@ -15,7 +15,8 @@ ;;; along with this program. If not, see ;;; . -(use-modules (sly game) +(use-modules (srfi srfi-26) + (sly game) (sly window) (sly utils) (sly signal) @@ -31,45 +32,58 @@ (load "common.scm") -(define crate-texture - (load-texture "images/crate.png")) +(define-signal crate-texture + (on-start (load-texture "images/crate.png"))) -(define sky-background - (load-sprite "images/country-sky.png")) +(define-signal sky-background + (on-start (load-sprite "images/country-sky.png"))) -(define forest-background - (load-sprite "images/country-trees.png")) +(define-signal forest-background + (on-start (load-sprite "images/country-trees.png"))) -(define background +(define (make-background sky forest) (scale 1/10 (move (vector3 0 0 -10) (render-begin - (render-sprite sky-background) - (render-sprite forest-background))))) + (render-sprite sky) + (render-sprite forest))))) -(define unit-cube - (make-cube 1 #:texture crate-texture)) +(define-signal background + (signal-map-maybe make-background + sky-background + forest-background)) -(define cubes +(define-signal unit-cube + (signal-map-maybe (cut make-cube 1 #:texture <>) + crate-texture)) + +(define (make-cubes unit-cube) (move (vector3 0 0 -3) (render-begin (move (vector3 2 0 0) unit-cube) unit-cube (move (vector3 -2 0 0) unit-cube)))) +(define-signal cubes + (signal-map-maybe make-cubes unit-cube)) + (define camera (3d-camera #:area (make-rect 0 0 640 480))) (define-signal scene (signal-let ((rotation (signal-map (lambda (x) (/ x 48)) - (signal-timer)))) - (with-camera camera - (render-begin - background - ;; Spinnin' cubes! - (with-depth-test #t - (rotate-x (* rotation 2) - (rotate-y rotation cubes))))))) + (signal-timer))) + (background background) + (cubes cubes)) + (if (and background cubes) + (with-camera camera + (render-begin + background + ;; Spinnin' cubes! + (with-depth-test #t + (rotate-x (* rotation 2) + (rotate-y rotation cubes))))) + render-nothing))) (with-window (make-window #:title "Shapes!") (run-game-loop scene)) -- cgit v1.2.3