summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/model.scm2
-rw-r--r--examples/path.scm3
-rw-r--r--examples/sprite-batch.scm16
-rw-r--r--examples/sprite.scm5
-rw-r--r--examples/text.scm6
-rw-r--r--examples/triangle.scm84
6 files changed, 104 insertions, 12 deletions
diff --git a/examples/model.scm b/examples/model.scm
index 4fa42c7..35aceb5 100644
--- a/examples/model.scm
+++ b/examples/model.scm
@@ -26,7 +26,7 @@
(reset-position))
(define (draw alpha)
- (with-projection projection
+ (with-graphics-state ((projection projection))
(draw-model model
#:model-matrix model-matrix
#:view-matrix view-matrix
diff --git a/examples/path.scm b/examples/path.scm
index 44cabdb..ef9bf8f 100644
--- a/examples/path.scm
+++ b/examples/path.scm
@@ -4,7 +4,8 @@
(chickadee graphics text)
(chickadee math)
(chickadee math vector)
- (chickadee scripting))
+ (chickadee scripting)
+ (ice-9 format))
(set! *random-state* (random-state-from-platform))
diff --git a/examples/sprite-batch.scm b/examples/sprite-batch.scm
index e62d1e4..cf79565 100644
--- a/examples/sprite-batch.scm
+++ b/examples/sprite-batch.scm
@@ -3,6 +3,7 @@
(chickadee math rect)
(chickadee math vector)
(chickadee graphics color)
+ (chickadee graphics path)
(chickadee graphics sprite)
(chickadee graphics text)
(chickadee graphics texture)
@@ -28,22 +29,28 @@
(define matrix (make-identity-matrix4))
(define (stats-message)
- (format #f "sprites: ~d fps: ~1,2f"
+ (format #f "sprites: ~d fps: ~1,2f"
num-sprites
(/ 1.0 avg-frame-time)))
-
+(define stats-text-pos (vec2 8.0 462.0))
(define stats-text (stats-message))
+(define stats-background
+ (with-style ((fill-color tango-light-plum))
+ (fill
+ (rounded-rectangle (vec2- stats-text-pos (vec2 4.0 4.0))
+ 212.0 18.0 #:radius 4.0))))
+(define stats-canvas (make-empty-canvas))
(define (load)
(set! *random-state* (random-state-from-platform))
(set! texture (load-image "images/shot.png"))
(set! batch (make-sprite-batch texture #:capacity num-sprites))
+ (set-canvas-painter! stats-canvas stats-background)
(script
(forever
(sleep 60)
(set! stats-text (pk 'stats (stats-message))))))
-(define stats-text-pos (vec2 4.0 464.0))
(define (draw alpha)
(sprite-batch-clear! batch)
(for-each (match-lambda
@@ -53,7 +60,8 @@
(sprite-batch-add* batch r matrix)))
sprites)
(draw-sprite-batch batch)
- (draw-text stats-text stats-text-pos #:color black)
+ (draw-canvas stats-canvas)
+ (draw-text stats-text stats-text-pos #:color tango-aluminium-6)
(let ((current-time (elapsed-time)))
(set! avg-frame-time
(+ (* (- current-time start-time) 0.1)
diff --git a/examples/sprite.scm b/examples/sprite.scm
index 24b7a24..753be4d 100644
--- a/examples/sprite.scm
+++ b/examples/sprite.scm
@@ -8,10 +8,11 @@
(define sprite #f)
(define (load)
- (pk (blending-factor-src 2))
(set! sprite (load-image "images/chickadee.png")))
(define (draw alpha)
- (draw-sprite sprite (vec2 256.0 176.0)))
+ (draw-sprite sprite (vec2 256.0 176.0))
+ ;;(abort-game)
+ )
(run-game #:load load #:draw draw)
diff --git a/examples/text.scm b/examples/text.scm
index be79edc..81e4021 100644
--- a/examples/text.scm
+++ b/examples/text.scm
@@ -7,7 +7,7 @@
(define avg-frame-time 16.0)
(define stats-text "")
(define stats-position (vec2 4.0 704.0))
-(define position (vec2 140.0 0.0))
+(define position (vec2 140.0 240.0))
(define text "The quick brown fox jumps over the lazy dog.\nFive hexing wizard bots jump quickly.")
(define (stats-message)
@@ -40,6 +40,4 @@
#:key-press key-press
#:load load
#:update update
- #:window-title "text rendering"
- #:window-width 1280
- #:window-height 720)
+ #:window-title "text rendering")
diff --git a/examples/triangle.scm b/examples/triangle.scm
new file mode 100644
index 0000000..2debc85
--- /dev/null
+++ b/examples/triangle.scm
@@ -0,0 +1,84 @@
+(use-modules (chickadee)
+ (chickadee math vector)
+ (chickadee graphics buffer)
+ (chickadee graphics engine)
+ (chickadee graphics shader))
+
+(use-modules (gl enums))
+
+(define vertex-array #f)
+(define shader #f)
+
+(define (load)
+ (define verts
+ (make-buffer #f32(0.0 0.0
+ 640.0 0.0
+ 320.0 480.0)))
+ (define colors
+ (make-buffer #f32(1.0 0.0 0.0 1.0
+ 0.0 1.0 0.0 1.0
+ 0.0 0.0 1.0 1.0)))
+ ;; This isn't necessary for a single triangle, but we're doing it
+ ;; anyway just to exercise that code.
+ (define indices (make-buffer #u32(0 1 2) #:target 'index))
+ (set! vertex-array
+ (make-vertex-array
+ #:indices (make-vertex-attribute
+ #:buffer indices
+ #:type 'scalar
+ #:component-type 'unsigned-int)
+ #:attributes `((0 . ,(make-vertex-attribute
+ #:buffer verts
+ #:type 'vec2
+ #:component-type 'float))
+ (1 . ,(make-vertex-attribute
+ #:buffer colors
+ #:type 'color
+ #:component-type 'float)))))
+ (set! shader (strings->shader
+ "
+#ifdef GLSL330
+layout (location = 0) in vec2 position;
+layout (location = 1) in vec4 color;
+#elif defined(GLSL130)
+in vec2 position;
+in vec4 color;
+#elif defined(GLSL120)
+attribute vec2 position;
+attribute vec4 color;
+#endif
+#ifdef GLSL120
+varying vec4 fragColor;
+#else
+out vec4 fragColor;
+#endif
+uniform mat4 mvp;
+
+void main(void) {
+ fragColor = color;
+ gl_Position = mvp * vec4(position, 0.0, 1.0);
+}
+"
+ "
+#ifdef GLSL120
+varying vec4 fragColor;
+#else
+in vec4 fragColor;
+ #endif
+#ifdef GLSL330
+out vec4 outFragColor;
+#endif
+
+void main (void) {
+#ifdef GLSL330
+ outFragColor = fragColor;
+#else
+ gl_FragColor = fragColor;
+#endif
+}
+")))
+
+(define (draw alpha)
+ (shader-apply shader vertex-array #:mvp (current-projection)))
+
+(run-game #:load load #:draw draw)