summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-09-21 19:47:47 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-09-21 19:48:44 -0400
commit88e22a04493153f3840965e15fe791bc9f870e3d (patch)
treed29de555c58f8ca778c309fa3fab1c16c46c8aca /examples
parent46544b7dba0081f22e686f70c606a338c7fa52dd (diff)
examples: Add framebuffer example.
* examples/framebuffer.scm: New file. * examples/Makefile.am (nobase_dist_examples_DATA): Add it.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am1
-rw-r--r--examples/framebuffer.scm64
2 files changed, 65 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 26ab508..4796503 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -20,6 +20,7 @@ nobase_dist_examples_DATA = \
animation.scm \
common.scm \
font.scm \
+ framebuffer.scm \
joystick.scm \
simple.scm \
tilemap.scm \
diff --git a/examples/framebuffer.scm b/examples/framebuffer.scm
new file mode 100644
index 0000000..894cbc3
--- /dev/null
+++ b/examples/framebuffer.scm
@@ -0,0 +1,64 @@
+;;; Sly
+;;; Copyright (C) 2015 David Thompson <davet@gnu.org>
+;;;
+;;; This program is free software: you can redistribute it and/or
+;;; modify it under the terms of the GNU General Public License as
+;;; published by the Free Software Foundation, either version 3 of the
+;;; License, or (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+(use-modules (sly game)
+ (sly window)
+ (sly utils)
+ (sly signal)
+ (sly math rect)
+ (sly math vector)
+ (sly render)
+ (sly render camera)
+ (sly render color)
+ (sly render framebuffer)
+ (sly render shader)
+ (sly render sprite)
+ (sly render texture))
+
+(load "common.scm")
+
+(define framebuffer
+ (make-framebuffer 320 240))
+
+(define inner-camera
+ (2d-camera #:area (make-rect 0 0 320 240)))
+
+(define outer-camera
+ (2d-camera #:area (make-rect 0 0 640 480)))
+
+(define inner-sprite
+ (load-sprite "images/p1_front.png"))
+
+(define outer-sprite
+ (make-sprite (framebuffer-texture framebuffer)
+ #:anchor 'bottom-left))
+
+(define-signal scene
+ (render-begin
+ (with-framebuffer framebuffer
+ (with-camera inner-camera
+ (move (vector2 160 120)
+ (render-sprite inner-sprite))))
+ (with-camera outer-camera
+ (scale 2 (render-sprite outer-sprite)))))
+
+(with-window (make-window #:title "Simple Sprite Demo")
+ (run-game-loop scene))
+
+;;; Local Variables:
+;;; compile-command: "../pre-inst-env guile simple.scm"
+;;; End: