summaryrefslogtreecommitdiff
path: root/examples/font.scm
blob: 8cdfd3a8d60d9028e582d63d07f5c842638e532b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(use-modules (figl gl)
             (2d color)
             (2d game-loop)
             (2d window)
             (2d helpers)
             (2d font))

(define window-width 800)
(define window-height 600)
(define font (load-font "fonts/Boxy-Bold.ttf" 48))
(define text "The quick brown fox jumped over the lazy dog.")
(define textbox (make-textbox font text #(320 300) white 'left 200))

;; Open the window.
(open-window window-width window-height)

(define (quit-demo)
  (close-window)
  (quit))

(define (key-down key mod unicode)
  (cond ((any-equal? key 'escape 'q)
         (quit-demo))))

;; Draw our sprite
(define (render)
  (let ((fps (floor (inexact->exact (current-fps)))))
    (with-gl-push-matrix
      (apply-color white)
      (draw-font font (format #f "FPS: ~d" fps))))
    (draw-textbox textbox))

;; Register callbacks.
(add-hook! on-quit-hook (lambda () (quit-demo)))
(add-hook! on-render-hook (lambda () (render)))
(add-hook! on-key-down-hook (lambda (key mod unicode) (key-down key mod unicode)))

;; Start the game loop.
;; The render callback will be called through this procedure.
(run-game-loop)