]> git.jsancho.org Git - guile-irrlicht.git/blob - irrlicht.scm
Scenes management and draw GUI elements
[guile-irrlicht.git] / irrlicht.scm
1 ;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
2 ;;; Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
3 ;;;
4 ;;; This file is part of guile-irrlicht.
5 ;;;
6 ;;; Guile-irrlicht is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation; either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; Guile-irrlicht is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ;;; General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with guile-irrlicht.  If not, see
18 ;;; <http://www.gnu.org/licenses/>.
19
20
21 (define-module (irrlicht)
22   #:use-module (ice-9 match)
23   #:use-module (system foreign)
24   #:use-module ((irrlicht bindings) #:prefix ffi:)
25   #:use-module ((irrlicht bindings core) #:prefix ffi-core:)
26   #:use-module ((irrlicht bindings gui) #:prefix ffi-gui:)
27   #:use-module ((irrlicht bindings video) #:prefix ffi-video:)
28   #:export (;; device
29             create-device
30             get-video-driver
31             get-gui-environment
32             get-scene-manager
33             set-window-caption!
34             device-run?
35             device-drop!
36             ;; driver
37             begin-scene
38             end-scene
39             ;; gui
40             add-static-text!
41             gui-draw-all))
42
43 ;; Device functions
44 (define* (create-device #:optional
45                         (device-type 'software)
46                         (window-size '(640 480))
47                         (bits 16)
48                         (fullscreen #f)
49                         (stencilbuffer #f)
50                         (vsync #f))
51   (let ((driver (match device-type
52                        ('null ffi-video:EDT_NULL)
53                        ('software ffi-video:EDT_SOFTWARE)
54                        ('burnings ffi-video:EDT_BURNINGSVIDEO)
55                        ('direct3d8 ffi-video:EDT_DIRECT3D8)
56                        ('direct3d9 ffi-video:EDT_DIRECT3D9)
57                        ('opengl ffi-video:EDT_OPENGL)
58                        ('count ffi-video:EDT_COUNT)))
59         (wsize (make-c-struct ffi-core:dimension2d window-size)))
60     (let ((device (ffi:create-device driver wsize bits
61                                      (if fullscreen 1 0)
62                                      (if stencilbuffer 1 0)
63                                      (if vsync 1 0))))
64       (if (null-pointer? device) #f device))))
65
66 (define (get-video-driver device)
67   (ffi:get-video-driver device))
68
69 (define (get-gui-environment device)
70   (ffi:get-gui-environment device))
71
72 (define (get-scene-manager device)
73   (ffi:get-scene-manager device))
74
75 (define (set-window-caption! device text)
76   (ffi:set-window-caption device (string->pointer text)))
77
78 (define (device-run? device)
79   (if (> (ffi:run device) 0) #t #f))
80
81 (define (device-drop! device)
82   (if (> (ffi:drop device) 0) #t #f))
83
84
85 ;; Driver functions
86 (define* (begin-scene driver
87                       #:optional
88                       (back-buffer #t)
89                       (z-buffer #t)
90                       (color '(255 0 0 0))
91                       (video-data %null-pointer)
92                       (source-rect '()))
93   (ffi-video:begin-scene driver
94                          (if back-buffer 1 0)
95                          (if z-buffer 1 0)
96                          (make-c-struct ffi-video:scolor color)
97                          video-data
98                          (if (null? source-rect)
99                              %null-pointer
100                              (make-c-struct ffi-core:rect source-rect))))
101
102 (define (end-scene driver)
103   (ffi-video:end-scene driver))
104
105
106 ;; GUI functions
107 (define* (add-static-text! gui-env text rectangle
108                            #:optional
109                            (border #f)
110                            (word-wrap #t)
111                            (parent %null-pointer)
112                            (id -1)
113                            (fill-background #f))
114   (ffi-gui:add-static-text gui-env
115                            (string->pointer text)
116                            (make-c-struct ffi-core:rect rectangle)
117                            (if border 1 0)
118                            (if word-wrap 1 0)
119                            parent
120                            id
121                            (if fill-background 1 0)))
122
123 (define (gui-draw-all gui-env)
124   (ffi-gui:draw-all gui-env))