1 ;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
2 ;;; Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
4 ;;; This file is part of guile-irrlicht.
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.
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.
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/>.
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:)
44 (define* (create-device #:optional
45 (device-type 'software)
46 (window-size '(640 480))
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
62 (if stencilbuffer 1 0)
64 (if (null-pointer? device) #f device))))
66 (define (get-video-driver device)
67 (ffi:get-video-driver device))
69 (define (get-gui-environment device)
70 (ffi:get-gui-environment device))
72 (define (get-scene-manager device)
73 (ffi:get-scene-manager device))
75 (define (set-window-caption! device text)
76 (ffi:set-window-caption device (string->pointer text)))
78 (define (device-run? device)
79 (if (> (ffi:run device) 0) #t #f))
81 (define (device-drop! device)
82 (if (> (ffi:drop device) 0) #t #f))
86 (define* (begin-scene driver
91 (video-data %null-pointer)
93 (ffi-video:begin-scene driver
96 (make-c-struct ffi-video:scolor color)
98 (if (null? source-rect)
100 (make-c-struct ffi-core:rect source-rect))))
102 (define (end-scene driver)
103 (ffi-video:end-scene driver))
107 (define* (add-static-text! gui-env text rectangle
111 (parent %null-pointer)
113 (fill-background #f))
114 (ffi-gui:add-static-text gui-env
115 (string->pointer text)
116 (make-c-struct ffi-core:rect rectangle)
121 (if fill-background 1 0)))
123 (define (gui-draw-all gui-env)
124 (ffi-gui:draw-all gui-env))