src/mesh.cpp \
src/mesh-scene-node.cpp \
src/position2d.cpp \
+ src/primitive-types.cpp \
src/rect.cpp \
src/reference-counted.cpp \
src/scene-manager.cpp \
(set! frames (+ frames 1))
(when (= frames 100)
(let ((fps (get-fps driver))
- (driver-name (get-video-driver-name driver)))
+ (driver-name (get-name driver)))
(let ((caption
(format #f "Irrlicht Engine [~a] FPS:~a" driver-name fps)))
(set-window-caption! device caption)))
--- /dev/null
+/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
+
+ Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
+
+ 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
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+#include "primitive-types.h"
+
+extern "C" {
+
+ irr::scene::E_PRIMITIVE_TYPE
+ scm_to_primitive_type (SCM primitive_type)
+ {
+ char* type = scm_to_utf8_stringn (scm_symbol_to_string (primitive_type), NULL);
+ if (!strcmp (type, "points"))
+ {
+ return irr::scene::EPT_POINTS;
+ }
+ else if (!strcmp (type, "line-strip"))
+ {
+ return irr::scene::EPT_LINE_STRIP;
+ }
+ else if (!strcmp (type, "line-loop"))
+ {
+ return irr::scene::EPT_LINE_LOOP;
+ }
+ else if (!strcmp (type, "lines"))
+ {
+ return irr::scene::EPT_LINES;
+ }
+ else if (!strcmp (type, "triangle-strip"))
+ {
+ return irr::scene::EPT_TRIANGLE_STRIP;
+ }
+ else if (!strcmp (type, "triangle-fan"))
+ {
+ return irr::scene::EPT_TRIANGLE_FAN;
+ }
+ else if (!strcmp (type, "triangles"))
+ {
+ return irr::scene::EPT_TRIANGLES;
+ }
+ else if (!strcmp (type, "quad-strip"))
+ {
+ return irr::scene::EPT_QUAD_STRIP;
+ }
+ else if (!strcmp (type, "quads"))
+ {
+ return irr::scene::EPT_QUADS;
+ }
+ else if (!strcmp (type, "polygon"))
+ {
+ return irr::scene::EPT_POLYGON;
+ }
+ else if (!strcmp (type, "point-sprites"))
+ {
+ return irr::scene::EPT_POINT_SPRITES;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong primitive type: ~S",
+ scm_list_1 (primitive_type), scm_list_1 (primitive_type));
+ }
+ }
+
+}
--- /dev/null
+/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
+
+ Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
+
+ 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
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __GUILE_IRRLICHT_PRIMITIVE_TYPES_H_INCLUDED__
+#define __GUILE_IRRLICHT_PRIMITIVE_TYPES_H_INCLUDED__
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+
+extern "C" {
+
+ irr::scene::E_PRIMITIVE_TYPE
+ scm_to_primitive_type (SCM primitive_type);
+
+}
+
+#endif
return scm_from_vector3df (s3dvertex->Pos);
}
+ irr::video::E_VERTEX_TYPE
+ scm_to_vertex_type (SCM vertex_type)
+ {
+ char* type = scm_to_utf8_stringn (scm_symbol_to_string (vertex_type), NULL);
+ if (!strcmp (type, "standard"))
+ {
+ return irr::video::EVT_STANDARD;
+ }
+ else if (!strcmp (type, "2tcoords"))
+ {
+ return irr::video::EVT_2TCOORDS;
+ }
+ else if (!strcmp (type, "tangents"))
+ {
+ return irr::video::EVT_TANGENTS;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong vertex_type: ~S",
+ scm_list_1 (vertex_type), scm_list_1 (vertex_type));
+ }
+ }
+
}
SCM
vertex3d_position (SCM vertex);
+ irr::video::E_VERTEX_TYPE
+ scm_to_vertex_type (SCM vertex_type);
+
}
#endif
#include "gui-environment.h"
#include "material.h"
#include "matrix4.h"
+#include "primitive-types.h"
#include "rect.h"
#include "scene-manager.h"
#include "texture.h"
+#include "vertex3d.h"
#include "video-driver.h"
#include "wrapped.h"
{
init_video_driver_type ();
scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene);
+ scm_c_define_gsubr ("draw-vertex-primitive-list", 3, 0, 1,
+ (scm_t_subr)irr_video_drawVertexPrimitiveList);
scm_c_define_gsubr ("end-scene", 1, 0, 0, (scm_t_subr)irr_video_endScene);
scm_c_define_gsubr ("get-fps", 1, 0, 0, (scm_t_subr)irr_video_getFPS);
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_define_gsubr ("set-transform!", 3, 0, 0, (scm_t_subr)irr_video_setTransform);
- scm_c_export ("begin-scene", "end-scene", "get-fps", "get-texture",
- "get-video-driver", "set-transform!", NULL);
+ scm_c_export ("begin-scene", "draw-vertex-primitive-list", "end-scene", "get-fps",
+ "get-texture", "get-video-driver", "set-transform!", NULL);
}
DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver",
sourceRectAddress));
}
+ SCM
+ irr_video_drawVertexPrimitiveList (SCM wrapped_video_driver,
+ SCM vertices,
+ SCM indices,
+ SCM rest)
+ {
+ SCM v_type = scm_from_utf8_symbol ("standard");
+ SCM p_type = scm_from_utf8_symbol ("triangles");
+
+ scm_c_bind_keyword_arguments ("draw-vertex-primitive-list", rest, (scm_t_keyword_arguments_flags)0,
+ scm_from_utf8_keyword ("vertex-type"), &v_type,
+ scm_from_utf8_keyword ("primitive-type"), &p_type,
+ SCM_UNDEFINED);
+
+ // Build vertex array
+ irr::u32 vertex_count = scm_to_uint32 (scm_length (vertices));
+ irr::video::S3DVertex s3d_vertices [vertex_count];
+ for (int i = 0; i < vertex_count; i++)
+ {
+ irr::video::S3DVertex* vertex = unwrap_vertex3d (scm_list_ref (vertices, scm_from_int (i)));
+ s3d_vertices[i] = irr::video::S3DVertex (vertex->Pos,
+ vertex->Normal,
+ vertex->Color,
+ vertex->TCoords);
+ }
+
+ // Build index array
+ irr::u32 index_count = scm_to_uint32 (scm_length (indices));
+ SCM flat_indices = scm_apply_0 (scm_eval_string (scm_from_utf8_string ("append")),
+ indices);
+ int flat_length = scm_to_int (scm_length (flat_indices));
+ irr::u32 c_indices [flat_length];
+ for (int i = 0; i < flat_length; i++)
+ {
+ c_indices[i] = scm_to_uint32 (scm_list_ref (flat_indices, scm_from_int (i)));
+ }
+
+ // Draw vertices
+ irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver);
+ driver->drawVertexPrimitiveList (&s3d_vertices[0],
+ vertex_count,
+ &c_indices[0],
+ index_count,
+ scm_to_vertex_type (v_type),
+ scm_to_primitive_type (p_type),
+ irr::video::EIT_32BIT);
+ return SCM_UNSPECIFIED;
+ }
+
SCM
irr_video_endScene (SCM wrapped_video_driver)
{
irr_video_beginScene (SCM wrapped_video_driver,
SCM rest);
+ SCM
+ irr_video_drawVertexPrimitiveList (SCM wrapped_video_driver,
+ SCM vertices,
+ SCM indices,
+ SCM rest);
+
SCM
irr_video_endScene (SCM wrapped_video_driver);