1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
3 Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
5 This file is part of guile-irrlicht.
7 guile-irrlicht is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 3 of the
10 License, or (at your option) any later version.
12 guile-irrlicht is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with guile-irrlicht. If not, see
19 <http://www.gnu.org/licenses/>.
22 #include <irrlicht/irrlicht.h>
27 #include "primitive-types.h"
30 #include "video-driver.h"
37 IVideoDriver_beginScene (SCM video_driver,
44 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
47 core::rect<s32>* sourceRectAddress = 0;
48 if (!scm_is_false (source_rect))
50 core::rect<s32> sourceRect = scm_to_rect_s32 (source_rect);
51 sourceRectAddress = &sourceRect;
54 return scm_from_bool (driver->beginScene (scm_to_bool (back_buffer),
55 scm_to_bool (z_buffer),
57 video::SExposedVideoData (),
62 IVideoDriver_drawVertexPrimitiveList (SCM video_driver,
69 u32 vertex_count = scm_to_uint32 (scm_length (vertices));
70 video::S3DVertex s3d_vertices [vertex_count];
71 for (int i = 0; i < vertex_count; i++)
73 video::S3DVertex* vertex =
74 (video::S3DVertex*) scm_to_irr_pointer (scm_list_ref (vertices, scm_from_int (i)));
75 s3d_vertices[i] = video::S3DVertex (vertex->Pos,
82 u32 index_count = scm_to_uint32 (scm_length (indices));
83 SCM flat_indices = scm_apply_0 (scm_eval_string (scm_from_utf8_string ("append")),
85 int flat_length = scm_to_int (scm_length (flat_indices));
86 u32 c_indices [flat_length];
87 for (int i = 0; i < flat_length; i++)
89 c_indices[i] = scm_to_uint32 (scm_list_ref (flat_indices, scm_from_int (i)));
93 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
94 driver->drawVertexPrimitiveList (&s3d_vertices[0],
98 scm_to_vertex_type (v_type),
99 scm_to_primitive_type (p_type),
101 return SCM_UNSPECIFIED;
105 IVideoDriver_endScene (SCM video_driver)
107 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
108 return scm_from_bool (driver->endScene ());
112 IVideoDriver_getFPS (SCM video_driver)
114 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
115 return scm_from_int32 (driver->getFPS ());
119 IVideoDriver_getName (SCM video_driver)
121 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
122 return scm_from_wide_char_string (driver->getName ());
126 IVideoDriver_getTexture (SCM video_driver,
129 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
130 video::ITexture* texture = driver->getTexture (scm_to_utf8_string (filename));
131 return scm_from_pointer ((void*) texture, NULL);
135 IVideoDriver_setMaterial (SCM video_driver,
138 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
139 driver->setMaterial (*((video::SMaterial*) scm_to_irr_pointer (material)));
140 return SCM_UNSPECIFIED;
144 IVideoDriver_setTransform (SCM video_driver,
148 video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
149 driver->setTransform (scm_to_transformation_state (state),
150 scm_to_matrix4 (mat));
151 return SCM_UNSPECIFIED;
156 init_video_driver (void)
158 DEFINE_GSUBR ("IVideoDriver_beginScene", 6, 0, 0, IVideoDriver_beginScene);
159 DEFINE_GSUBR ("IVideoDriver_drawVertexPrimitiveList", 5, 0, 1,
160 IVideoDriver_drawVertexPrimitiveList);
161 DEFINE_GSUBR ("IVideoDriver_endScene", 1, 0, 0, IVideoDriver_endScene);
162 DEFINE_GSUBR ("IVideoDriver_getFPS", 1, 0, 0, IVideoDriver_getFPS);
163 DEFINE_GSUBR ("IVideoDriver_getName", 1, 0, 0, IVideoDriver_getName);
164 DEFINE_GSUBR ("IVideoDriver_getTexture", 2, 0, 0, IVideoDriver_getTexture);
165 DEFINE_GSUBR ("IVideoDriver_setMaterial", 2, 0, 0, IVideoDriver_setMaterial);
166 DEFINE_GSUBR ("IVideoDriver_setTransform", 3, 0, 0, IVideoDriver_setTransform);
169 video::E_TRANSFORMATION_STATE
170 scm_to_transformation_state (SCM transformation_state)
172 char* state = scm_to_utf8_string (scm_symbol_to_string (transformation_state));
173 if (!strcmp (state, "view"))
175 return video::ETS_VIEW;
177 else if (!strcmp (state, "world"))
179 return video::ETS_WORLD;
181 else if (!strcmp (state, "projection"))
183 return video::ETS_PROJECTION;
185 else if (!strcmp (state, "texture0"))
187 return video::ETS_TEXTURE_0;
189 else if (!strcmp (state, "texture1"))
191 return video::ETS_TEXTURE_1;
193 else if (!strcmp (state, "texture2"))
195 return video::ETS_TEXTURE_2;
197 else if (!strcmp (state, "texture3"))
199 return video::ETS_TEXTURE_3;
203 scm_error (scm_arg_type_key, NULL, "Wrong transformation state: ~S",
204 scm_list_1 (transformation_state), scm_list_1 (transformation_state));