]> git.jsancho.org Git - guile-irrlicht.git/blob - irrlicht/video.scm
6c56f62776c86290d16642b76e7e2c8b157b0b2a
[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 ;; SMaterial
36 (define-class <material> (<irrlicht-base>)
37   (irr-class #:init-value "SMaterial"))
38
39 (define* (make-material #:key
40                         (material-type 'solid)
41                         (ambient-color '(255 255 255 255))
42                         (diffuse-color '(255 255 255 255))
43                         (emissive-color '(0 0 0 0))
44                         (specular-color '(255 255 255 255))
45                         (shininess 0)
46                         (material-type-param 0)
47                         (material-type-param-2 0)
48                         (thickness 1)
49                         (z-buffer 'less-equal)
50                         (anti-aliasing 'simple)
51                         (color-mask 'all)
52                         (color-material 'diffuse)
53                         (blend-operation 'none)
54                         (polygon-offset-factor 0)
55                         (polygon-offset-direction 'front)
56                         (wireframe #f)
57                         (point-cloud #f)
58                         (gouraud-shading #t)
59                         (lighting #t)
60                         (z-write-enable #t)
61                         (backface-culling #t)
62                         (frontface-culling #f)
63                         (fog-enable #f)
64                         (normalize-normals #f)
65                         (use-mip-maps #t))
66   (let ((SMaterial_make (get-irrlicht-proc "SMaterial_make")))
67     (make <material>
68       #:irr-pointer
69       (SMaterial_make #:material-type material-type #:ambient-color ambient-color
70                       #:diffuse-color diffuse-color #:emissive-color emissive-color
71                       #:specular-color specular-color #:shininess shininess
72                       #:material-type-param material-type-param
73                       #:material-type-param-2 material-type-param-2
74                       #:thickness thickness #:z-buffer z-buffer #:anti-aliasing anti-aliasing
75                       #:color-mask color-mask #:color-material color-material
76                       #:blend-operation blend-operation
77                       #:polygon-offset-factor polygon-offset-factor
78                       #:polygon-offset-direction polygon-offset-direction
79                       #:wireframe wireframe #:point-cloud point-cloud
80                       #:gouraud-shading gouraud-shading #:lighting lighting
81                       #:z-write-enable z-write-enable #:backface-culling backface-culling
82                       #:frontface-culling frontface-culling #:fog-enable fog-enable
83                       #:normalize-normals normalize-normals #:use-mip-maps use-mip-maps))))
84
85 (export <material> make-material)
86
87
88 ;; IVideoDriver
89 (define-class <video-driver> (<irrlicht-base>)
90   (irr-class #:init-value "IVideoDriver"))
91
92 (define-method (begin-scene (video-driver <video-driver>) . rest)
93   (let-keywords rest #f
94         ((back-buffer #t)
95          (z-buffer #t)
96          (color '(255 0 0 0))
97          video-data
98          source-rect)
99     ((get-irrlicht-proc "beginScene" video-driver)
100      video-driver
101      back-buffer
102      z-buffer
103      color
104      video-data
105      source-rect)))
106
107 (define-method (draw-vertex-primitive-list (video-driver <video-driver>) vertices indices . rest)
108   (let-keywords rest #f
109         ((v-type 'standard)
110          (p-type 'triangles))
111     (let ((drawVertexPrimitiveList (get-irrlicht-proc "drawVertexPrimitiveList" video-driver)))
112       (drawVertexPrimitiveList video-driver vertices indices v-type p-type))))
113
114 (define-method (end-scene (video-driver <video-driver>))
115   ((get-irrlicht-proc "endScene" video-driver)
116    video-driver))
117
118 (define-method (get-fps (video-driver <video-driver>))
119   (let ((getFPS (get-irrlicht-proc "getFPS" video-driver)))
120     (getFPS video-driver)))
121
122 (define-method (get-name (video-driver <video-driver>))
123   (let ((getName (get-irrlicht-proc "getName" video-driver)))
124     (getName video-driver)))
125
126 (define-method (get-texture (video-driver <video-driver>) filename)
127   (make <texture>
128     #:irr-pointer
129     ((get-irrlicht-proc "getTexture" video-driver)
130      video-driver
131      filename)))
132
133 (define-method (set-material! (video-driver <video-driver>) (material <material>))
134   (let ((setMaterial (get-irrlicht-proc "setMaterial" video-driver)))
135     (setMaterial video-driver material)))
136
137 (define-method (set-transform! (video-driver <video-driver>) state mat)
138   (let ((setTransform (get-irrlicht-proc "setTransform" video-driver)))
139     (setTransform video-driver state mat)))
140
141 (export <video-driver> begin-scene draw-vertex-primitive-list end-scene get-fps get-name get-texture
142         set-material! set-transform!)
143
144
145 ;; S3DVertex
146 (define-class <vertex3d> (<irrlicht-base>)
147   (irr-class #:init-value "S3DVertex"))
148
149 (define-method (get-position (vertex3d <vertex3d>))
150   (let ((S3DVertex_Pos (get-irrlicht-proc "S3DVertex_Pos")))
151     (S3DVertex_Pos vertex3d)))
152
153 (define (make-vertex3d position normal color tcoords)
154   (let ((S3DVertex_make (get-irrlicht-proc "S3DVertex_make")))
155     (make <vertex3d>
156       #:irr-pointer
157       (S3DVertex_make position normal color tcoords))))
158
159 (export <vertex3d> get-position make-vertex3d)