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>
28 #include "material-types.h"
36 init_material_type ();
37 DEFINE_GSUBR ("make-material", 0, 0, 1, make_material);
40 DEFINE_WRAPPED_TYPE (irr::video::SMaterial*, "material",
41 init_material_type, material_p,
42 wrap_material, unwrap_material);
45 make_material (SCM rest)
47 SCM material_type = scm_from_utf8_symbol ("solid");
48 SCM ambient_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
49 scm_from_uint32 (255), scm_from_uint32 (255));
50 SCM diffuse_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
51 scm_from_uint32 (255), scm_from_uint32 (255));
52 SCM emissive_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
53 scm_from_uint32 (255), scm_from_uint32 (255));
54 SCM specular_color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (255),
55 scm_from_uint32 (255), scm_from_uint32 (255));
56 SCM shininess = scm_from_double (0.0f);
57 SCM material_type_param = scm_from_double (0.0f);
58 SCM material_type_param_2 = scm_from_double (0.0f);
59 SCM thickness = scm_from_double (1.0f);
60 SCM z_buffer = scm_from_utf8_symbol ("less-equal");
61 SCM anti_aliasing = scm_from_utf8_symbol ("simple");
62 SCM color_mask = scm_from_utf8_symbol ("all");
63 SCM color_material = scm_from_utf8_symbol ("diffuse");
64 SCM blend_operation = scm_from_utf8_symbol ("none");
65 SCM polygon_offset_factor = scm_from_uint8 (0);
66 SCM polygon_offset_direction = scm_from_utf8_symbol ("front");
67 SCM wireframe = SCM_BOOL_F;
68 SCM point_cloud = SCM_BOOL_F;
69 SCM gouraud_shading = SCM_BOOL_T;
70 SCM lighting = SCM_BOOL_T;
71 SCM z_write_enable = SCM_BOOL_T;
72 SCM backface_culling = SCM_BOOL_T;
73 SCM frontface_culling = SCM_BOOL_F;
74 SCM fog_enable = SCM_BOOL_F;
75 SCM normalize_normals = SCM_BOOL_F;
76 SCM use_mip_maps = SCM_BOOL_T;
78 scm_c_bind_keyword_arguments
79 ("make-material", rest, (scm_t_keyword_arguments_flags)0,
80 scm_from_utf8_keyword ("material-type"), &material_type,
81 scm_from_utf8_keyword ("ambient-color"), &ambient_color,
82 scm_from_utf8_keyword ("diffuse-color"), &diffuse_color,
83 scm_from_utf8_keyword ("emissive-color"), &emissive_color,
84 scm_from_utf8_keyword ("specular-color"), &specular_color,
85 scm_from_utf8_keyword ("shininess"), &shininess,
86 scm_from_utf8_keyword ("material-type-param"), &material_type_param,
87 scm_from_utf8_keyword ("material-type-param-2"), &material_type_param_2,
88 scm_from_utf8_keyword ("thickness"), &thickness,
89 scm_from_utf8_keyword ("z-buffer"), &z_buffer,
90 scm_from_utf8_keyword ("anti-aliasing"), &anti_aliasing,
91 scm_from_utf8_keyword ("color-mask"), &color_mask,
92 scm_from_utf8_keyword ("color-material"), &color_material,
93 scm_from_utf8_keyword ("blend-operation"), &blend_operation,
94 scm_from_utf8_keyword ("polygon-offset-factor"), &polygon_offset_factor,
95 scm_from_utf8_keyword ("polygon-offset-direction"), &polygon_offset_direction,
96 scm_from_utf8_keyword ("wireframe"), &wireframe,
97 scm_from_utf8_keyword ("point-cloud"), &point_cloud,
98 scm_from_utf8_keyword ("gouraud-shading"), &gouraud_shading,
99 scm_from_utf8_keyword ("lighting"), &lighting,
100 scm_from_utf8_keyword ("z-write-enable"), &z_write_enable,
101 scm_from_utf8_keyword ("backface-culling"), &backface_culling,
102 scm_from_utf8_keyword ("frontface-culling"), &frontface_culling,
103 scm_from_utf8_keyword ("fog-enable"), &fog_enable,
104 scm_from_utf8_keyword ("normalize-normals"), &normalize_normals,
105 scm_from_utf8_keyword ("use-mip-maps"), &use_mip_maps,
108 irr::video::SMaterial* material = new irr::video::SMaterial ();
109 material->MaterialType = scm_to_material_type(material_type);
110 material->AmbientColor = scm_to_color (ambient_color);
111 material->DiffuseColor = scm_to_color (diffuse_color);
112 material->EmissiveColor = scm_to_color (emissive_color);
113 material->SpecularColor = scm_to_color (specular_color);
114 material->Shininess = scm_to_double (shininess);
115 material->MaterialTypeParam = scm_to_double (material_type_param);
116 material->MaterialTypeParam2 = scm_to_double (material_type_param_2);
117 material->Thickness = scm_to_double (thickness);
118 material->ZBuffer = scm_to_comparison_func (z_buffer);
119 material->AntiAliasing = scm_to_anti_aliasing_mode (anti_aliasing);
120 material->ColorMask = scm_to_color_plane (color_mask);
121 material->ColorMaterial = scm_to_color_material (color_material);
122 material->BlendOperation = scm_to_blend_operation (blend_operation);
123 material->PolygonOffsetFactor = scm_to_uint8 (polygon_offset_factor);
124 material->PolygonOffsetDirection = scm_to_polygon_offset (polygon_offset_direction);
125 material->Wireframe = scm_to_bool (wireframe);
126 material->PointCloud = scm_to_bool (point_cloud);
127 material->GouraudShading = scm_to_bool (gouraud_shading);
128 material->Lighting = scm_to_bool (lighting);
129 material->ZWriteEnable = scm_to_bool (z_write_enable);
130 material->BackfaceCulling = scm_to_bool (backface_culling);
131 material->FrontfaceCulling = scm_to_bool (frontface_culling);
132 material->FogEnable = scm_to_bool (fog_enable);
133 material->NormalizeNormals = scm_to_bool (normalize_normals);
134 material->UseMipMaps = scm_to_bool (use_mip_maps);
135 return wrap_material (material);
138 irr::video::E_ANTI_ALIASING_MODE
139 scm_to_anti_aliasing_mode (SCM anti_aliasing_mode)
141 char* mode = scm_to_utf8_stringn (scm_symbol_to_string (anti_aliasing_mode), NULL);
142 if (!strcmp (mode, "off"))
144 return irr::video::EAAM_OFF;
146 else if (!strcmp (mode, "simple"))
148 return irr::video::EAAM_SIMPLE;
150 else if (!strcmp (mode, "quality"))
152 return irr::video::EAAM_QUALITY;
154 else if (!strcmp (mode, "line-smooth"))
156 return irr::video::EAAM_LINE_SMOOTH;
158 else if (!strcmp (mode, "point-smooth"))
160 return irr::video::EAAM_POINT_SMOOTH;
162 else if (!strcmp (mode, "full-basic"))
164 return irr::video::EAAM_FULL_BASIC;
166 else if (!strcmp (mode, "alpha-to-coverage"))
168 return irr::video::EAAM_ALPHA_TO_COVERAGE;
172 scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S",
173 scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode));
177 irr::video::E_BLEND_OPERATION
178 scm_to_blend_operation (SCM blend_operation)
180 char* operation = scm_to_utf8_stringn (scm_symbol_to_string (blend_operation), NULL);
181 if (!strcmp (operation, "none"))
183 return irr::video::EBO_NONE;
185 else if (!strcmp (operation, "add"))
187 return irr::video::EBO_ADD;
189 else if (!strcmp (operation, "subtract"))
191 return irr::video::EBO_SUBTRACT;
193 else if (!strcmp (operation, "rev-subtract"))
195 return irr::video::EBO_REVSUBTRACT;
197 else if (!strcmp (operation, "min"))
199 return irr::video::EBO_MIN;
201 else if (!strcmp (operation, "max"))
203 return irr::video::EBO_MAX;
205 else if (!strcmp (operation, "min-factor"))
207 return irr::video::EBO_MIN_FACTOR;
209 else if (!strcmp (operation, "max-factor"))
211 return irr::video::EBO_MAX_FACTOR;
213 else if (!strcmp (operation, "min-alpha"))
215 return irr::video::EBO_MIN_ALPHA;
217 else if (!strcmp (operation, "max-alpha"))
219 return irr::video::EBO_MAX_ALPHA;
223 scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S",
224 scm_list_1 (blend_operation), scm_list_1 (blend_operation));
228 irr::video::E_COLOR_MATERIAL
229 scm_to_color_material (SCM color_material)
231 char* material = scm_to_utf8_stringn (scm_symbol_to_string (color_material), NULL);
232 if (!strcmp (material, "none"))
234 return irr::video::ECM_NONE;
236 else if (!strcmp (material, "diffuse"))
238 return irr::video::ECM_DIFFUSE;
240 else if (!strcmp (material, "ambient"))
242 return irr::video::ECM_AMBIENT;
244 else if (!strcmp (material, "emissive"))
246 return irr::video::ECM_EMISSIVE;
248 else if (!strcmp (material, "specular"))
250 return irr::video::ECM_SPECULAR;
252 else if (!strcmp (material, "diffuse-and-ambient"))
254 return irr::video::ECM_DIFFUSE_AND_AMBIENT;
258 scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S",
259 scm_list_1 (color_material), scm_list_1 (color_material));
263 irr::video::E_COLOR_PLANE
264 scm_to_color_plane (SCM color_plane)
266 char* plane = scm_to_utf8_stringn (scm_symbol_to_string (color_plane), NULL);
267 if (!strcmp (plane, "none"))
269 return irr::video::ECP_NONE;
271 else if (!strcmp (plane, "alpha"))
273 return irr::video::ECP_ALPHA;
275 else if (!strcmp (plane, "red"))
277 return irr::video::ECP_RED;
279 else if (!strcmp (plane, "green"))
281 return irr::video::ECP_GREEN;
283 else if (!strcmp (plane, "blue"))
285 return irr::video::ECP_BLUE;
287 else if (!strcmp (plane, "rgb"))
289 return irr::video::ECP_RGB;
291 else if (!strcmp (plane, "all"))
293 return irr::video::ECP_ALL;
297 scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S",
298 scm_list_1 (color_plane), scm_list_1 (color_plane));
302 irr::video::E_COMPARISON_FUNC
303 scm_to_comparison_func (SCM comparison_func)
305 char* func = scm_to_utf8_stringn (scm_symbol_to_string (comparison_func), NULL);
306 if (!strcmp (func, "never"))
308 return irr::video::ECFN_NEVER;
310 else if (!strcmp (func, "less-equal"))
312 return irr::video::ECFN_LESSEQUAL;
314 else if (!strcmp (func, "equal"))
316 return irr::video::ECFN_EQUAL;
318 else if (!strcmp (func, "less"))
320 return irr::video::ECFN_LESS;
322 else if (!strcmp (func, "not-equal"))
324 return irr::video::ECFN_NOTEQUAL;
326 else if (!strcmp (func, "greater-equal"))
328 return irr::video::ECFN_GREATEREQUAL;
330 else if (!strcmp (func, "greater"))
332 return irr::video::ECFN_GREATER;
334 else if (!strcmp (func, "always"))
336 return irr::video::ECFN_ALWAYS;
340 scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S",
341 scm_list_1 (comparison_func), scm_list_1 (comparison_func));
345 irr::video::E_POLYGON_OFFSET
346 scm_to_polygon_offset (SCM polygon_offset)
348 char* offset = scm_to_utf8_stringn (scm_symbol_to_string (polygon_offset), NULL);
349 if (!strcmp (offset, "back"))
351 return irr::video::EPO_BACK;
353 else if (!strcmp (offset, "front"))
355 return irr::video::EPO_FRONT;
359 scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S",
360 scm_list_1 (polygon_offset), scm_list_1 (polygon_offset));