X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=irrlicht%2Fvideo.scm;h=0c334fe2d84344b7c101136ce55a7a3908448c5c;hb=8994b42fea213a741631efbe7fd9c09c0aab7100;hp=a394c01b667de8580b8dd1877f599b8fd385a9eb;hpb=916ccc1a2ce8a81d8c611fc976fc537d6048dd47;p=guile-irrlicht.git diff --git a/irrlicht/video.scm b/irrlicht/video.scm index a394c01..0c334fe 100644 --- a/irrlicht/video.scm +++ b/irrlicht/video.scm @@ -19,16 +19,21 @@ (define-module (irrlicht video) + #:use-module (ice-9 match) #:use-module (system foreign) #:use-module ((irrlicht bindings core) #:prefix ffi-core:) + #:use-module ((irrlicht bindings scene) #:prefix ffi-scene:) #:use-module ((irrlicht bindings video) #:prefix ffi-video:) #:use-module (irrlicht util) #:use-module (irrlicht util foreign) #:export (begin-scene + draw-vertex-primitive-list end-scene get-fps get-texture get-video-driver-name + set-material! + set-transform! make-s3dvertex vertex-position make-material)) @@ -49,6 +54,57 @@ %null-pointer (ffi-core:rect->pointer source-rect)))) +(define* (draw-vertex-primitive-list driver vertices index-list + #:key + (v-type 'standard) + (p-type 'triangles)) + (define (make-c-vertices vertices) + (let ((vals (map (lambda (vertex) + (parse-c-struct (ffi-video:s3dvertex->pointer vertex) + ffi-video:s3dvertex)) + vertices)) + (types (make-list (length vertices) ffi-video:s3dvertex))) + (make-c-struct types vals))) + + (define (make-c-indices indices) + (let* ((vals (apply append indices)) + (types (make-list (length vals) int32))) + (make-c-struct types vals))) + + (let ((vertices-pointer (make-c-vertices vertices)) + (vertex-count (length vertices)) + (indices-pointer (make-c-indices index-list)) + (prim-count (length index-list)) + (vertex-type + (match v-type + ('standard ffi-video:EVT_STANDARD) + ('2tcoords ffi-video:EVT_2TCOORDS) + ('tangents ffi-video:EVT_TANGENTS))) + (primitive-type + (match p-type + ('points ffi-scene:EPT_POINTS) + ('strip ffi-scene:EPT_LINE_STRIP) + ('line-loop ffi-scene:EPT_LINE_LOOP) + ('lines ffi-scene:EPT_LINES) + ('triangle-strip ffi-scene:EPT_TRIANGLE_STRIP) + ('triangle-fan ffi-scene:EPT_TRIANGLE_FAN) + ('triangles ffi-scene:EPT_TRIANGLES) + ('quad-strip ffi-scene:EPT_QUAD_STRIP) + ('quads ffi-scene:EPT_QUADS) + ('polygon ffi-scene:EPT_POLYGON) + ('point-sprites ffi-scene:EPT_POINT_SPRITES)))) + + + (ffi-video:draw-vertex-primitive-list + driver + vertices-pointer + vertex-count + indices-pointer + prim-count + vertex-type + primitive-type + ffi-video:EIT_32BIT))) + (define (end-scene driver) (ffi-video:end-scene driver)) @@ -62,6 +118,31 @@ (pointer->string (ffi-video:get-video-driver-name driver))) +(define (set-material! driver material) + (ffi-video:set-material + driver + (ffi-video:smaterial->pointer material))) + +(define (set-transform! driver state mat) + (let ((transform-state + (match state + ('view ffi-video:ETS_VIEW) + ('world ffi-video:ETS_WORLD) + ('projection ffi-video:ETS_PROJECTION) + ('texture0 ffi-video:ETS_TEXTURE_0) + ('texture1 ffi-video:ETS_TEXTURE_1) + ('texture2 ffi-video:ETS_TEXTURE_2) + ('texture3 ffi-video:ETS_TEXTURE_3) + ('texture4 ffi-video:ETS_TEXTURE_4) + ('texture5 ffi-video:ETS_TEXTURE_5) + ('texture6 ffi-video:ETS_TEXTURE_6) + ('texture7 ffi-video:ETS_TEXTURE_7) + ('count ffi-video:ETS_COUNT)))) + (ffi-video:set-transform + driver + transform-state + mat))) + ;; s3d vertices (define (make-s3dvertex position normal color t-coords) (ffi-video:pointer->s3dvertex @@ -111,4 +192,8 @@ (bool->integer #t) ; useMipMaps )))) (ffi-video:pointer->smaterial - (make-c-struct+ ffi-video:smaterial material)))) + ;; (make-c-struct+ ffi-video:smaterial material)))) + (make-c-material)))) + +(define-public (make-c-material) + (ffi-video:make-c-material))