From 88e22a04493153f3840965e15fe791bc9f870e3d Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 21 Sep 2015 19:47:47 -0400 Subject: examples: Add framebuffer example. * examples/framebuffer.scm: New file. * examples/Makefile.am (nobase_dist_examples_DATA): Add it. --- examples/Makefile.am | 1 + examples/framebuffer.scm | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 examples/framebuffer.scm (limited to 'examples') 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 +;;; +;;; 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 +;;; . + +(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: -- cgit v1.2.3