]> git.jsancho.org Git - guile-irrlicht.git/blob - irrlicht/video.scm
9acfa1853c7cc3272286e5ee5d7ebcfb78f7f1a0
[guile-irrlicht.git] / irrlicht / video.scm
1 ;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
2 ;;; Copyright (C) 2020 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 video)
22   #:use-module (oop goops)
23   #:use-module (ice-9 optargs)
24   #:use-module (irrlicht base)
25   #:use-module (irrlicht foreign))
26
27
28 ;; ITexture
29 (define-class <texture> (<irrlicht-base>)
30   (irr-class #:init-value "ITexture"))
31
32 (export <texture>)
33
34
35 ;; IVideoDriver
36 (define-class <video-driver> (<irrlicht-base>)
37   (irr-class #:init-value "IVideoDriver"))
38
39 (define-method (begin-scene (video-driver <video-driver>) . rest)
40   (let-keywords rest #f
41         ((back-buffer #t)
42          (z-buffer #t)
43          (color '(255 0 0 0))
44          video-data
45          source-rect)
46     ((get-irrlicht-proc "beginScene" video-driver)
47      video-driver
48      back-buffer
49      z-buffer
50      color
51      video-data
52      source-rect)))
53
54 (define-method (end-scene (video-driver <video-driver>))
55   ((get-irrlicht-proc "endScene" video-driver)
56    video-driver))
57
58 (define-method (get-fps (video-driver <video-driver>))
59   (let ((getFPS (get-irrlicht-proc "getFPS" video-driver)))
60     (getFPS video-driver)))
61
62 (define-method (get-name (video-driver <video-driver>))
63   (let ((getName (get-irrlicht-proc "getName" video-driver)))
64     (getName video-driver)))
65
66 (define-method (get-texture (video-driver <video-driver>) filename)
67   (make <texture>
68     #:irr-pointer
69     ((get-irrlicht-proc "getTexture" video-driver)
70      video-driver
71      filename)))
72
73 (export <video-driver> begin-scene end-scene get-fps get-name get-texture)
74
75
76 ;; S3DVertex
77 (define-class <vertex3d> (<irrlicht-base>)
78   (irr-class #:init-value "S3DVertex"))
79
80 (define (make-vertex3d position normal color tcoords)
81   (let ((S3DVertex_make (get-irrlicht-proc "S3DVertex_make")))
82     (make <vertex3d>
83       #:irr-pointer
84       (S3DVertex_make position normal color tcoords))))
85
86 (export <vertex3d> make-vertex3d)
87
88
89 ;; SMaterial
90 (define-class <material> (<irrlicht-base>)
91   (irr-class #:init-value "SMaterial"))
92
93 (define* (make-material #:key
94                         (material-type 'solid)
95                         (ambient-color '(255 255 255 255))
96                         (diffuse-color '(255 255 255 255))
97                         (emissive-color '(0 0 0 0))
98                         (specular-color '(255 255 255 255))
99                         (shininess 0)
100                         (material-type-param 0)
101                         (material-type-param-2 0)
102                         (thickness 1)
103                         (z-buffer 'less-equal)
104                         (anti-aliasing 'simple)
105                         (color-mask 'all)
106                         (color-material 'diffuse)
107                         (blend-operation 'none)
108                         (polygon-offset-factor 0)
109                         (polygon-offset-direction 'front)
110                         (wireframe #f)
111                         (point-cloud #f)
112                         (gouraud-shading #t)
113                         (lighting #t)
114                         (z-write-enable #t)
115                         (backface-culling #t)
116                         (frontface-culling #f)
117                         (fog-enable #f)
118                         (normalize-normals #f)
119                         (use-mip-maps #t))
120   (let ((SMaterial_make (get-irrlicht-proc "SMaterial_make")))
121     (make <material>
122       #:irr-pointer
123       (SMaterial_make #:material-type material-type #:ambient-color ambient-color
124                       #:diffuse-color diffuse-color #:emissive-color emissive-color
125                       #:specular-color specular-color #:shininess shininess
126                       #:material-type-param material-type-param
127                       #:material-type-param-2 material-type-param-2
128                       #:thickness thickness #:z-buffer z-buffer #:anti-aliasing anti-aliasing
129                       #:color-mask color-mask #:color-material color-material
130                       #:blend-operation blend-operation
131                       #:polygon-offset-factor polygon-offset-factor
132                       #:polygon-offset-direction polygon-offset-direction
133                       #:wireframe wireframe #:point-cloud point-cloud
134                       #:gouraud-shading gouraud-shading #:lighting lighting
135                       #:z-write-enable z-write-enable #:backface-culling backface-culling
136                       #:frontface-culling frontface-culling #:fog-enable fog-enable
137                       #:normalize-normals normalize-normals #:use-mip-maps use-mip-maps))))
138
139 (export <material> make-material)