summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2019-06-11 08:04:33 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2019-06-11 08:04:33 -0400
commitdd243dd72e2b1dd6d190816d97e814a0a0187a43 (patch)
treeab42e1a5e6cda661fea8d0053f19886998d1a640
parent68c66e4c7942e2c993b6a1b11a7e26011ff486a9 (diff)
node-2d: Respect desired viewport in <view-2d>.
-rw-r--r--starling/node-2d.scm29
1 files changed, 24 insertions, 5 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm
index e63d64d..663942c 100644
--- a/starling/node-2d.scm
+++ b/starling/node-2d.scm
@@ -179,15 +179,34 @@
(define-class <view-2d> ()
(camera #:accessor camera #:init-keyword #:camera)
- (area #:getter area #:init-keyword #:area))
+ (area #:getter area #:init-keyword #:area)
+ (viewport #:accessor viewport)
+ (projection-matrix #:accessor projection-matrix)
+ (sprite-rect #:accessor sprite-rect))
+
+(define-method (initialize (view <view-2d>) initargs)
+ (next-method)
+ (let* ((area (area view))
+ (x (rect-x area))
+ (y (rect-y area))
+ (w (rect-width area))
+ (h (rect-height area)))
+ (set! (viewport view)
+ (make-viewport (inexact->exact x)
+ (inexact->exact y)
+ (inexact->exact w)
+ (inexact->exact h)))
+ (set! (sprite-rect view) (make-rect 0.0 0.0 w h))
+ (set! (projection-matrix view) (orthographic-projection 0 w h 0 0 1))))
(define %identity-matrix (make-identity-matrix4))
(define-method (render (view <view-2d>))
- (with-projection (projection-matrix (camera view))
- (draw-sprite* (framebuffer-texture (framebuffer (camera view)))
- (area view)
- %identity-matrix)))
+ (with-viewport (viewport view)
+ (with-projection (projection-matrix view)
+ (draw-sprite* (framebuffer-texture (framebuffer (camera view)))
+ (sprite-rect view)
+ %identity-matrix))))
;;;