]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/video-driver.cpp
Define procedures with keywords from C code
[guile-irrlicht.git] / src / video-driver.cpp
index c746db3ae313727d9f7c42a3b6d8958755ec9d67..57231a6d2623bd342aa934df16b4a9ccbefcd7d7 100644 (file)
 
 #include <irrlicht/irrlicht.h>
 #include <libguile.h>
+
+#include "color.h"
+#include "device.h"
+#include "rect.h"
+#include "texture.h"
 #include "video-driver.h"
 #include "wrapped.h"
 
@@ -30,10 +35,74 @@ extern "C" {
   init_video_driver (void)
   {
     init_video_driver_type ();
+    scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene);
+    scm_c_define_gsubr ("get-texture", 2, 0, 0, (scm_t_subr)irr_video_getTexture);
+    scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver);
+    scm_c_export ("begin-scene", "get-texture", "get-video-driver", NULL);
   }
 
   DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver",
                        init_video_driver_type, video_driver_p,
                        wrap_video_driver, unwrap_video_driver);
 
+  SCM
+  irr_video_beginScene (SCM wrapped_video_driver,
+                        SCM rest)
+  {
+    SCM back_buffer = scm_from_bool(1);
+    SCM z_buffer = scm_from_bool(1);
+    SCM color = scm_list_4 (scm_from_uint32 (255),
+                            scm_from_uint32 (0),
+                            scm_from_uint32 (0),
+                            scm_from_uint32 (0));
+    SCM video_data = scm_from_bool(0);
+    SCM source_rect = scm_from_bool(0);
+
+    scm_c_bind_keyword_arguments ("begin-scene", rest, (scm_t_keyword_arguments_flags)0,
+                                  scm_from_utf8_keyword ("back-buffer"), &back_buffer,
+                                  scm_from_utf8_keyword ("z-buffer"), &z_buffer,
+                                  scm_from_utf8_keyword ("color"), &color,
+                                  scm_from_utf8_keyword ("video-data"), &video_data,
+                                  scm_from_utf8_keyword ("source-rect"), &source_rect,
+                                  SCM_UNDEFINED);
+
+    irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver);
+    irr::core::rect<irr::s32>* sourceRectAddress = 0;
+    if (!scm_is_false (source_rect))
+      {
+        irr::core::rect<irr::s32> sourceRect = scm_to_rect_s32 (source_rect);
+        sourceRectAddress = &sourceRect;
+      }
+    return scm_from_bool (driver->beginScene (scm_to_bool (back_buffer),
+                                              scm_to_bool (z_buffer),
+                                              scm_to_color (color),
+                                              irr::video::SExposedVideoData (),
+                                              sourceRectAddress));
+  }
+
+  SCM
+  irr_video_getTexture (SCM wrapped_video_driver,
+                        SCM filename)
+  {
+    irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver);
+    irr::video::ITexture* texture = driver->getTexture (scm_to_utf8_stringn (filename, NULL));
+    return wrap_texture (texture);
+  }
+
+  SCM
+  irr_getVideoDriver (SCM wrapped_obj)
+  {
+    irr::video::IVideoDriver* driver;
+    if (device_p (wrapped_obj))
+      {
+        driver = unwrap_device (wrapped_obj)->getVideoDriver ();
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot get video driver from object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+    return wrap_video_driver (driver);
+  }
+
 }