From fb9011bf9160be890e0a6b98fcff9ed95ae0bd77 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 16 Mar 2020 19:14:38 +0100 Subject: [PATCH] set-material-texture! get-texture --- Makefile.am | 4 +++- irrlicht.scm | 3 ++- irrlicht/scene.scm | 1 + irrlicht/video.scm | 24 ++++++++++++++++++++++++ src/guile-irrlicht.cpp | 2 ++ src/scene-node.cpp | 28 ++++++++++++++++++++++++++++ src/scene-node.h | 6 ++++++ src/texture.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/texture.h | 39 +++++++++++++++++++++++++++++++++++++++ src/video-driver.cpp | 11 +++++++++++ src/video-driver.h | 4 ++++ 11 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 irrlicht/video.scm create mode 100644 src/texture.cpp create mode 100644 src/texture.h diff --git a/Makefile.am b/Makefile.am index a641056..2a5fc9e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,7 @@ libguile_irrlicht_la_SOURCES = \ src/reference-counted.cpp \ src/scene-manager.cpp \ src/scene-node.cpp \ + src/texture.cpp \ src/vector3d.cpp \ src/video-driver.cpp \ src/wchar.cpp @@ -72,4 +73,5 @@ SOURCES = \ irrlicht/device.scm \ irrlicht/gui.scm \ irrlicht/irr.scm \ - irrlicht/scene.scm + irrlicht/scene.scm \ + irrlicht/video.scm diff --git a/irrlicht.scm b/irrlicht.scm index 1b635f2..57ecbbc 100644 --- a/irrlicht.scm +++ b/irrlicht.scm @@ -26,7 +26,8 @@ '((irrlicht device) (irrlicht gui) (irrlicht irr) - (irrlicht scene))) + (irrlicht scene) + (irrlicht video))) (current-interface (module-public-interface (current-module)))) (for-each diff --git a/irrlicht/scene.scm b/irrlicht/scene.scm index 0053b93..f3191a0 100644 --- a/irrlicht/scene.scm +++ b/irrlicht/scene.scm @@ -22,6 +22,7 @@ #:export (add-animated-mesh-scene-node get-mesh set-material-flag! + set-material-texture! set-md2-animation!)) (load-extension "libguile-irrlicht" "init_guile_irrlicht") diff --git a/irrlicht/video.scm b/irrlicht/video.scm new file mode 100644 index 0000000..77e3d21 --- /dev/null +++ b/irrlicht/video.scm @@ -0,0 +1,24 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2020 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +(define-module (irrlicht video) + #:export (get-texture)) + +(load-extension "libguile-irrlicht" "init_guile_irrlicht") diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index d80a5dc..898815e 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -31,6 +31,7 @@ #include "reference-counted.h" #include "scene-manager.h" #include "scene-node.h" +#include "texture.h" #include "video-driver.h" extern "C" { @@ -48,6 +49,7 @@ extern "C" { init_reference_counted (); init_scene_manager (); init_scene_node (); + init_texture (); init_video_driver (); } diff --git a/src/scene-node.cpp b/src/scene-node.cpp index d392aba..16ddbf6 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -21,7 +21,9 @@ #include #include +#include "animated-mesh-scene-node.h" #include "scene-node.h" +#include "texture.h" #include "wrapped.h" extern "C" { @@ -30,10 +32,36 @@ extern "C" { init_scene_node (void) { init_scene_node_type (); + scm_c_define_gsubr ("set-material-texture!", 3, 0, 0, (scm_t_subr)irr_scene_setMaterialTexture); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneNode*, "scene-node", init_scene_node_type, scene_node_p, wrap_scene_node, unwrap_scene_node); + SCM + irr_scene_setMaterialTexture (SCM wrapped_scene_node, + SCM texture_layer, + SCM texture) + { + if (animated_mesh_scene_node_p (wrapped_scene_node)) + { + unwrap_animated_mesh_scene_node (wrapped_scene_node)-> + setMaterialTexture (scm_to_uint32 (texture_layer), + unwrap_texture (texture)); + } + else if (scene_node_p (wrapped_scene_node)) + { + unwrap_scene_node (wrapped_scene_node)-> + setMaterialTexture (scm_to_uint32 (texture_layer), + unwrap_texture (texture)); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set material texture to object: ~S", + scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); + } + return SCM_UNSPECIFIED; + } + } diff --git a/src/scene-node.h b/src/scene-node.h index 64c3626..c41d3cc 100644 --- a/src/scene-node.h +++ b/src/scene-node.h @@ -33,6 +33,12 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::scene::ISceneNode*, init_scene_node_type, scene_node_p, wrap_scene_node, unwrap_scene_node); + + SCM + irr_scene_setMaterialTexture (SCM wrapped_scene_node, + SCM texture_layer, + SCM texture); + } #endif diff --git a/src/texture.cpp b/src/texture.cpp new file mode 100644 index 0000000..5dba655 --- /dev/null +++ b/src/texture.cpp @@ -0,0 +1,38 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "texture.h" + +extern "C" { + + void + init_texture (void) + { + init_texture_type (); + } + + DEFINE_WRAPPED_TYPE (irr::video::ITexture*, "texture", + init_texture_type, texture_p, + wrap_texture, unwrap_texture); + +} diff --git a/src/texture.h b/src/texture.h new file mode 100644 index 0000000..f6c1ec9 --- /dev/null +++ b/src/texture.h @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_IRRLICHT_TEXTURE_H_INCLUDED__ +#define __GUILE_IRRLICHT_TEXTURE_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_texture (void); + + DECLARE_WRAPPED_TYPE (irr::video::ITexture*, init_texture_type, + texture_p, wrap_texture, unwrap_texture); + +} + +#endif diff --git a/src/video-driver.cpp b/src/video-driver.cpp index b768f58..632f0de 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -23,6 +23,7 @@ #include #include "device.h" +#include "texture.h" #include "video-driver.h" #include "wrapped.h" @@ -32,6 +33,7 @@ extern "C" { init_video_driver (void) { init_video_driver_type (); + 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); } @@ -39,6 +41,15 @@ extern "C" { init_video_driver_type, video_driver_p, wrap_video_driver, unwrap_video_driver); + 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) { diff --git a/src/video-driver.h b/src/video-driver.h index 7e3f727..5137ca4 100644 --- a/src/video-driver.h +++ b/src/video-driver.h @@ -34,6 +34,10 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::video::IVideoDriver*, init_video_driver_type, video_driver_p, wrap_video_driver, unwrap_video_driver); + SCM + irr_video_getTexture (SCM wrapped_video_driver, + SCM filename); + SCM irr_getVideoDriver (SCM wrapped_obj); -- 2.39.5