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 video)
22 #:use-module (ice-9 match)
23 #:use-module (system foreign)
24 #:use-module ((irrlicht bindings core) #:prefix ffi-core:)
25 #:use-module ((irrlicht bindings video) #:prefix ffi-video:)
26 #:use-module (irrlicht util)
27 #:use-module (irrlicht util foreign)
39 (define* (begin-scene driver
44 (video-data %null-pointer)
46 (ffi-video:begin-scene driver
47 (bool->integer back-buffer)
48 (bool->integer z-buffer)
49 (ffi-video:scolor->pointer color)
51 (if (null? source-rect)
53 (ffi-core:rect->pointer source-rect))))
55 (define (end-scene driver)
56 (ffi-video:end-scene driver))
58 (define (get-fps driver)
59 (ffi-video:get-fps driver))
61 (define (get-texture driver filename)
62 (ffi-video:get-texture driver (string->pointer filename)))
64 (define (get-video-driver-name driver)
66 (ffi-video:get-video-driver-name driver)))
68 (define (set-material! driver material)
69 (ffi-video:set-material
71 (ffi-video:smaterial->pointer material)))
73 (define (set-transform! driver state mat)
74 (let ((transform-state
76 ('view ffi-video:ETS_VIEW)
77 ('world ffi-video:ETS_WORLD)
78 ('projection ffi-video:ETS_PROJECTION)
79 ('texture0 ffi-video:ETS_TEXTURE_0)
80 ('texture1 ffi-video:ETS_TEXTURE_1)
81 ('texture2 ffi-video:ETS_TEXTURE_2)
82 ('texture3 ffi-video:ETS_TEXTURE_3)
83 ('texture4 ffi-video:ETS_TEXTURE_4)
84 ('texture5 ffi-video:ETS_TEXTURE_5)
85 ('texture6 ffi-video:ETS_TEXTURE_6)
86 ('texture7 ffi-video:ETS_TEXTURE_7)
87 ('count ffi-video:ETS_COUNT))))
88 (ffi-video:set-transform
94 (define (make-s3dvertex position normal color t-coords)
95 (ffi-video:pointer->s3dvertex
96 (make-c-struct ffi-video:s3dvertex
97 (list position normal color t-coords))))
99 (define (vertex-position vertex)
100 (let ((data (parse-c-struct (ffi-video:s3dvertex->pointer vertex)
101 ffi-video:s3dvertex)))
105 (define* (make-material #:key (wireframe #f) (lighting #t))
109 (list %null-pointer 0 0 0 0 0 0 %null-pointer %null-pointer)
110 (list %null-pointer 0 0 0 0 0 0 %null-pointer %null-pointer)
111 (list %null-pointer 0 0 0 0 0 0 %null-pointer %null-pointer)
112 (list %null-pointer 0 0 0 0 0 0 %null-pointer %null-pointer)
113 ffi-video:EMT_SOLID ; materialType
114 (list 255 255 255 255) ; ambientColor
115 (list 255 255 255 255) ; diffuseColor
116 (list 0 0 0 0) ; emissiveColor
117 (list 255 255 255 255) ; specularColor
119 0 ; materialTypeParam
120 0 ; materialTypeParam2
122 ffi-video:ECFN_LESSEQUAL ; zBuffer
123 ffi-video:EAAM_SIMPLE ; antiAliasing
125 ffi-video:ECP_ALL ; colorMask
126 ffi-video:ECM_DIFFUSE ; colorMaterial
127 ffi-video:EBO_NONE ; blendOperation
128 0 ; polygonOffsetFactor
129 ffi-video:EPO_FRONT ; polygonOffsetDirection
130 (bool->integer wireframe) ; wireframe
131 (bool->integer #f) ; pointCloud
132 (bool->integer #t) ; gouraudShading
133 (bool->integer lighting) ; lighting
134 (bool->integer #t) ; zWriteEnable
135 (bool->integer #t) ; backfaceCulling
136 (bool->integer #f) ; frontfaceCulling
137 (bool->integer #f) ; fogEnable
138 (bool->integer #f) ; normalizeNormals
139 (bool->integer #t) ; useMipMaps
141 (ffi-video:pointer->smaterial
142 (make-c-struct+ ffi-video:smaterial material))))