--- /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 "material-types.h"
+
+extern "C" {
+
+ irr::video::E_MATERIAL_TYPE
+ scm_to_material_type (SCM material_type)
+ {
+ char* type = scm_to_utf8_stringn (scm_symbol_to_string (material_type), NULL);
+ if (!strcmp (type, "solid"))
+ {
+ return irr::video::EMT_SOLID;
+ }
+ else if (!strcmp (type, "solid-2-layer"))
+ {
+ return irr::video::EMT_SOLID_2_LAYER;
+ }
+ else if (!strcmp (type, "lightmap"))
+ {
+ return irr::video::EMT_LIGHTMAP;
+ }
+ else if (!strcmp (type, "lightmap-add"))
+ {
+ return irr::video::EMT_LIGHTMAP_ADD;
+ }
+ else if (!strcmp (type, "lightmap-m2"))
+ {
+ return irr::video::EMT_LIGHTMAP_M2;
+ }
+ else if (!strcmp (type, "lightmap-m4"))
+ {
+ return irr::video::EMT_LIGHTMAP_M4;
+ }
+ else if (!strcmp (type, "lightmap-lighting"))
+ {
+ return irr::video::EMT_LIGHTMAP_LIGHTING;
+ }
+ else if (!strcmp (type, "lightmap-lighting-m2"))
+ {
+ return irr::video::EMT_LIGHTMAP_LIGHTING_M2;
+ }
+ else if (!strcmp (type, "lightmap-lighting-m4"))
+ {
+ return irr::video::EMT_LIGHTMAP_LIGHTING_M4;
+ }
+ else if (!strcmp (type, "detail-map"))
+ {
+ return irr::video::EMT_DETAIL_MAP;
+ }
+ else if (!strcmp (type, "sphere-map"))
+ {
+ return irr::video::EMT_SPHERE_MAP;
+ }
+ else if (!strcmp (type, "reflection-2-layer"))
+ {
+ return irr::video::EMT_REFLECTION_2_LAYER;
+ }
+ else if (!strcmp (type, "transparent-add-color"))
+ {
+ return irr::video::EMT_TRANSPARENT_ADD_COLOR;
+ }
+ else if (!strcmp (type, "transparent-alpha-channel"))
+ {
+ return irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ }
+ else if (!strcmp (type, "transparent-alpha-channel-ref"))
+ {
+ return irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ }
+ else if (!strcmp (type, "transparent-vertex-alpha"))
+ {
+ return irr::video::EMT_TRANSPARENT_VERTEX_ALPHA;
+ }
+ else if (!strcmp (type, "transparent-reflection-2-layer"))
+ {
+ return irr::video::EMT_TRANSPARENT_REFLECTION_2_LAYER;
+ }
+ else if (!strcmp (type, "normal-map-solid"))
+ {
+ return irr::video::EMT_NORMAL_MAP_SOLID;
+ }
+ else if (!strcmp (type, "normal-map-transparent-add-color"))
+ {
+ return irr::video::EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR;
+ }
+ else if (!strcmp (type, "normal-map-transparent-vertex-alpha"))
+ {
+ return irr::video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA;
+ }
+ else if (!strcmp (type, "parallax-map-solid"))
+ {
+ return irr::video::EMT_PARALLAX_MAP_SOLID;
+ }
+ else if (!strcmp (type, "parallax-map-transparent-add-color"))
+ {
+ return irr::video::EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR;
+ }
+ else if (!strcmp (type, "parallax-map-transparent-vertex-alpha"))
+ {
+ return irr::video::EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA;
+ }
+ else if (!strcmp (type, "onetexture-blend"))
+ {
+ return irr::video::EMT_ONETEXTURE_BLEND;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong material type: ~S",
+ scm_list_1 (material_type), scm_list_1 (material_type));
+ }
+ }
+
+}
#include <irrlicht/irrlicht.h>
#include <libguile.h>
+
+#include "color.h"
#include "material.h"
+#include "material-types.h"
#include "wrapped.h"
extern "C" {
SCM
make_material (SCM rest)
{
+ SCM material_type = scm_from_utf8_symbol ("solid");
+ SCM ambient_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
+ scm_from_uint32 (255), scm_from_uint32 (255));
+ SCM diffuse_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
+ scm_from_uint32 (255), scm_from_uint32 (255));
+ SCM emissive_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
+ scm_from_uint32 (255), scm_from_uint32 (255));
+ SCM specular_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
+ scm_from_uint32 (255), scm_from_uint32 (255));
+ SCM shininess = scm_from_double (0.0f);
+ SCM material_type_param = scm_from_double (0.0f);
+ SCM material_type_param_2 = scm_from_double (0.0f);
+ SCM thickness = scm_from_double (1.0f);
+ SCM z_buffer = scm_from_utf8_symbol ("less-equal");
+ SCM anti_aliasing = scm_from_utf8_symbol ("simple");
+ SCM color_mask = scm_from_utf8_symbol ("all");
+ SCM color_material = scm_from_utf8_symbol ("diffuse");
+ SCM blend_operation = scm_from_utf8_symbol ("none");
+ SCM polygon_offset_factor = scm_from_uint8 (0);
+ SCM polygon_offset_direction = scm_from_utf8_symbol ("front");
SCM wireframe = scm_from_bool (0);
+ SCM point_cloud = scm_from_bool (0);
+ SCM gouraud_shading = scm_from_bool (1);
SCM lighting = scm_from_bool (1);
+ SCM z_write_enable = scm_from_bool (1);
+ SCM backface_culling = scm_from_bool (1);
+ SCM frontface_culling = scm_from_bool (0);
+ SCM fog_enable = scm_from_bool (0);
+ SCM normalize_normals = scm_from_bool (0);
+ SCM use_mip_maps = scm_from_bool (1);
- scm_c_bind_keyword_arguments ("make-material", rest, (scm_t_keyword_arguments_flags)0,
- scm_from_utf8_keyword ("wireframe"), &wireframe,
- scm_from_utf8_keyword ("lighting"), &lighting,
- SCM_UNDEFINED);
+ scm_c_bind_keyword_arguments
+ ("make-material", rest, (scm_t_keyword_arguments_flags)0,
+ scm_from_utf8_keyword ("material-type"), &material_type,
+ scm_from_utf8_keyword ("ambient-color"), &ambient_color,
+ scm_from_utf8_keyword ("diffuse-color"), &diffuse_color,
+ scm_from_utf8_keyword ("emissive-color"), &emissive_color,
+ scm_from_utf8_keyword ("specular-color"), &specular_color,
+ scm_from_utf8_keyword ("shininess"), &shininess,
+ scm_from_utf8_keyword ("material-type-param"), &material_type_param,
+ scm_from_utf8_keyword ("material-type-param-2"), &material_type_param_2,
+ scm_from_utf8_keyword ("thickness"), &thickness,
+ scm_from_utf8_keyword ("z-buffer"), &z_buffer,
+ scm_from_utf8_keyword ("anti-aliasing"), &anti_aliasing,
+ scm_from_utf8_keyword ("color-mask"), &color_mask,
+ scm_from_utf8_keyword ("color-material"), &color_material,
+ scm_from_utf8_keyword ("blend-operation"), &blend_operation,
+ scm_from_utf8_keyword ("polygon-offset-factor"), &polygon_offset_factor,
+ scm_from_utf8_keyword ("polygon-offset-direction"), &polygon_offset_direction,
+ scm_from_utf8_keyword ("wireframe"), &wireframe,
+ scm_from_utf8_keyword ("point-cloud"), &point_cloud,
+ scm_from_utf8_keyword ("gouraud-shading"), &gouraud_shading,
+ scm_from_utf8_keyword ("lighting"), &lighting,
+ scm_from_utf8_keyword ("z-write-enable"), &z_write_enable,
+ scm_from_utf8_keyword ("backface-culling"), &backface_culling,
+ scm_from_utf8_keyword ("frontface-culling"), &frontface_culling,
+ scm_from_utf8_keyword ("fog-enable"), &fog_enable,
+ scm_from_utf8_keyword ("normalize-normals"), &normalize_normals,
+ scm_from_utf8_keyword ("use-mip-maps"), &use_mip_maps,
+ SCM_UNDEFINED);
irr::video::SMaterial* material = new irr::video::SMaterial ();
- material->Wireframe = wireframe;
- material->Lighting = lighting;
+ material->MaterialType = scm_to_material_type(material_type);
+ material->AmbientColor = scm_to_color (ambient_color);
+ material->DiffuseColor = scm_to_color (diffuse_color);
+ material->EmissiveColor = scm_to_color (emissive_color);
+ material->SpecularColor = scm_to_color (specular_color);
+ material->Shininess = scm_to_double (shininess);
+ material->MaterialTypeParam = scm_to_double (material_type_param);
+ material->MaterialTypeParam2 = scm_to_double (material_type_param_2);
+ material->Thickness = scm_to_double (thickness);
+ material->ZBuffer = scm_to_comparison_func (z_buffer);
+ material->AntiAliasing = scm_to_anti_aliasing_mode (anti_aliasing);
+ material->ColorMask = scm_to_color_plane (color_mask);
+ material->ColorMaterial = scm_to_color_material (color_material);
+ material->BlendOperation = scm_to_blend_operation (blend_operation);
+ material->PolygonOffsetFactor = scm_to_uint8 (polygon_offset_factor);
+ material->PolygonOffsetDirection = scm_to_polygon_offset (polygon_offset_direction);
+ material->Wireframe = scm_to_bool (wireframe);
+ material->PointCloud = scm_to_bool (point_cloud);
+ material->GouraudShading = scm_to_bool (gouraud_shading);
+ material->Lighting = scm_to_bool (lighting);
+ material->ZWriteEnable = scm_to_bool (z_write_enable);
+ material->BackfaceCulling = scm_to_bool (backface_culling);
+ material->FrontfaceCulling = scm_to_bool (frontface_culling);
+ material->FogEnable = scm_to_bool (fog_enable);
+ material->NormalizeNormals = scm_to_bool (normalize_normals);
+ material->UseMipMaps = scm_to_bool (use_mip_maps);
return wrap_material (material);
}
+ irr::video::E_ANTI_ALIASING_MODE
+ scm_to_anti_aliasing_mode (SCM anti_aliasing_mode)
+ {
+ char* mode = scm_to_utf8_stringn (scm_symbol_to_string (anti_aliasing_mode), NULL);
+ if (!strcmp (mode, "off"))
+ {
+ return irr::video::EAAM_OFF;
+ }
+ else if (!strcmp (mode, "simple"))
+ {
+ return irr::video::EAAM_SIMPLE;
+ }
+ else if (!strcmp (mode, "quality"))
+ {
+ return irr::video::EAAM_QUALITY;
+ }
+ else if (!strcmp (mode, "line-smooth"))
+ {
+ return irr::video::EAAM_LINE_SMOOTH;
+ }
+ else if (!strcmp (mode, "point-smooth"))
+ {
+ return irr::video::EAAM_POINT_SMOOTH;
+ }
+ else if (!strcmp (mode, "full-basic"))
+ {
+ return irr::video::EAAM_FULL_BASIC;
+ }
+ else if (!strcmp (mode, "alpha-to-coverage"))
+ {
+ return irr::video::EAAM_ALPHA_TO_COVERAGE;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S",
+ scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode));
+ }
+ }
+
+ irr::video::E_BLEND_OPERATION
+ scm_to_blend_operation (SCM blend_operation)
+ {
+ char* operation = scm_to_utf8_stringn (scm_symbol_to_string (blend_operation), NULL);
+ if (!strcmp (operation, "none"))
+ {
+ return irr::video::EBO_NONE;
+ }
+ else if (!strcmp (operation, "add"))
+ {
+ return irr::video::EBO_ADD;
+ }
+ else if (!strcmp (operation, "subtract"))
+ {
+ return irr::video::EBO_SUBTRACT;
+ }
+ else if (!strcmp (operation, "rev-subtract"))
+ {
+ return irr::video::EBO_REVSUBTRACT;
+ }
+ else if (!strcmp (operation, "min"))
+ {
+ return irr::video::EBO_MIN;
+ }
+ else if (!strcmp (operation, "max"))
+ {
+ return irr::video::EBO_MAX;
+ }
+ else if (!strcmp (operation, "min-factor"))
+ {
+ return irr::video::EBO_MIN_FACTOR;
+ }
+ else if (!strcmp (operation, "max-factor"))
+ {
+ return irr::video::EBO_MAX_FACTOR;
+ }
+ else if (!strcmp (operation, "min-alpha"))
+ {
+ return irr::video::EBO_MIN_ALPHA;
+ }
+ else if (!strcmp (operation, "max-alpha"))
+ {
+ return irr::video::EBO_MAX_ALPHA;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S",
+ scm_list_1 (blend_operation), scm_list_1 (blend_operation));
+ }
+ }
+
+ irr::video::E_COLOR_MATERIAL
+ scm_to_color_material (SCM color_material)
+ {
+ char* material = scm_to_utf8_stringn (scm_symbol_to_string (color_material), NULL);
+ if (!strcmp (material, "none"))
+ {
+ return irr::video::ECM_NONE;
+ }
+ else if (!strcmp (material, "diffuse"))
+ {
+ return irr::video::ECM_DIFFUSE;
+ }
+ else if (!strcmp (material, "ambient"))
+ {
+ return irr::video::ECM_AMBIENT;
+ }
+ else if (!strcmp (material, "emissive"))
+ {
+ return irr::video::ECM_EMISSIVE;
+ }
+ else if (!strcmp (material, "specular"))
+ {
+ return irr::video::ECM_SPECULAR;
+ }
+ else if (!strcmp (material, "diffuse-and-ambient"))
+ {
+ return irr::video::ECM_DIFFUSE_AND_AMBIENT;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S",
+ scm_list_1 (color_material), scm_list_1 (color_material));
+ }
+ }
+
+ irr::video::E_COLOR_PLANE
+ scm_to_color_plane (SCM color_plane)
+ {
+ char* plane = scm_to_utf8_stringn (scm_symbol_to_string (color_plane), NULL);
+ if (!strcmp (plane, "none"))
+ {
+ return irr::video::ECP_NONE;
+ }
+ else if (!strcmp (plane, "alpha"))
+ {
+ return irr::video::ECP_ALPHA;
+ }
+ else if (!strcmp (plane, "red"))
+ {
+ return irr::video::ECP_RED;
+ }
+ else if (!strcmp (plane, "green"))
+ {
+ return irr::video::ECP_GREEN;
+ }
+ else if (!strcmp (plane, "blue"))
+ {
+ return irr::video::ECP_BLUE;
+ }
+ else if (!strcmp (plane, "rgb"))
+ {
+ return irr::video::ECP_RGB;
+ }
+ else if (!strcmp (plane, "all"))
+ {
+ return irr::video::ECP_ALL;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S",
+ scm_list_1 (color_plane), scm_list_1 (color_plane));
+ }
+ }
+
+ irr::video::E_COMPARISON_FUNC
+ scm_to_comparison_func (SCM comparison_func)
+ {
+ char* func = scm_to_utf8_stringn (scm_symbol_to_string (comparison_func), NULL);
+ if (!strcmp (func, "never"))
+ {
+ return irr::video::ECFN_NEVER;
+ }
+ else if (!strcmp (func, "less-equal"))
+ {
+ return irr::video::ECFN_LESSEQUAL;
+ }
+ else if (!strcmp (func, "equal"))
+ {
+ return irr::video::ECFN_EQUAL;
+ }
+ else if (!strcmp (func, "less"))
+ {
+ return irr::video::ECFN_LESS;
+ }
+ else if (!strcmp (func, "not-equal"))
+ {
+ return irr::video::ECFN_NOTEQUAL;
+ }
+ else if (!strcmp (func, "greater-equal"))
+ {
+ return irr::video::ECFN_GREATEREQUAL;
+ }
+ else if (!strcmp (func, "greater"))
+ {
+ return irr::video::ECFN_GREATER;
+ }
+ else if (!strcmp (func, "always"))
+ {
+ return irr::video::ECFN_ALWAYS;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S",
+ scm_list_1 (comparison_func), scm_list_1 (comparison_func));
+ }
+ }
+
+ irr::video::E_POLYGON_OFFSET
+ scm_to_polygon_offset (SCM polygon_offset)
+ {
+ char* offset = scm_to_utf8_stringn (scm_symbol_to_string (polygon_offset), NULL);
+ if (!strcmp (offset, "back"))
+ {
+ return irr::video::EPO_BACK;
+ }
+ else if (!strcmp (offset, "front"))
+ {
+ return irr::video::EPO_FRONT;
+ }
+ else
+ {
+ scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S",
+ scm_list_1 (polygon_offset), scm_list_1 (polygon_offset));
+ }
+ }
+
}