]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - irrlicht/video.scm
Custom Scene Node example
[guile-irrlicht.git] / irrlicht / video.scm
index dc61f644279cb1e90e18e4c45fc2a42065d697b2..0c334fe2d84344b7c101136ce55a7a3908448c5c 100644 (file)
   #: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
                              %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))
 
            (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))