diff options
Diffstat (limited to 'chickadee/graphics/viewport.scm')
-rw-r--r-- | chickadee/graphics/viewport.scm | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/chickadee/graphics/viewport.scm b/chickadee/graphics/viewport.scm index 5fd2e9b..b60a585 100644 --- a/chickadee/graphics/viewport.scm +++ b/chickadee/graphics/viewport.scm @@ -1,5 +1,5 @@ ;;; Chickadee Game Toolkit -;;; Copyright © 2017 David Thompson <davet@gnu.org> +;;; Copyright © 2017, 2021 David Thompson <davet@gnu.org> ;;; ;;; Chickadee is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published @@ -27,8 +27,8 @@ #:use-module (gl) #:use-module (chickadee utils) #:use-module (chickadee graphics color) + #:use-module (chickadee graphics engine) #:use-module (chickadee graphics gl) - #:use-module (chickadee graphics gpu) #:export (make-viewport viewport? viewport-x @@ -38,8 +38,8 @@ viewport-clear-color viewport-clear-flags null-viewport - apply-viewport clear-viewport + current-viewport %default-clear-flags %default-clear-color)) @@ -93,8 +93,8 @@ CLEAR-FLAGS are 'color-buffer', 'depth-buffer', 'accum-buffer', and ('color-buffer 16384)) flags))))) -(define (clear-viewport viewport) - (gl-clear (clear-buffer-mask (viewport-clear-flags viewport)))) +(define (clear-viewport) + (gl-clear (clear-buffer-mask (viewport-clear-flags (current-viewport))))) (define (apply-viewport viewport) "Set the OpenGL state for VIEWPORT. Clip rendering to the viewport @@ -109,3 +109,22 @@ area, set the clear color, and clear necessary buffers." (gl-viewport x y w h) (gl-scissor x y w h) (gl-clear-color (color-r c) (color-g c) (color-b c) (color-a c))))) + +(define (bind-viewport viewport) + "Set the OpenGL state for VIEWPORT. Clip rendering to the viewport +area, and set the clear color.." + (unless (eq? viewport null-viewport) + (let ((x (viewport-x viewport)) + (y (viewport-y viewport)) + (w (viewport-width viewport)) + (h (viewport-height viewport)) + (c (viewport-clear-color viewport))) + (gl-enable (enable-cap scissor-test)) + (gl-viewport x y w h) + (gl-scissor x y w h) + (gl-clear-color (color-r c) (color-g c) (color-b c) (color-a c))))) + +(define-graphics-state viewport + current-viewport + #:default null-viewport + #:bind bind-viewport) |