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"
34 SMaterial_make (SCM rest)
42 SCM material_type_param;
43 SCM material_type_param_2;
50 SCM polygon_offset_factor;
51 SCM polygon_offset_direction;
58 SCM frontface_culling;
60 SCM normalize_normals;
63 scm_c_bind_keyword_arguments
64 ("video_SMaterial_make", rest, (scm_t_keyword_arguments_flags)0,
65 scm_from_utf8_keyword ("material-type"), &material_type,
66 scm_from_utf8_keyword ("ambient-color"), &ambient_color,
67 scm_from_utf8_keyword ("diffuse-color"), &diffuse_color,
68 scm_from_utf8_keyword ("emissive-color"), &emissive_color,
69 scm_from_utf8_keyword ("specular-color"), &specular_color,
70 scm_from_utf8_keyword ("shininess"), &shininess,
71 scm_from_utf8_keyword ("material-type-param"), &material_type_param,
72 scm_from_utf8_keyword ("material-type-param-2"), &material_type_param_2,
73 scm_from_utf8_keyword ("thickness"), &thickness,
74 scm_from_utf8_keyword ("z-buffer"), &z_buffer,
75 scm_from_utf8_keyword ("anti-aliasing"), &anti_aliasing,
76 scm_from_utf8_keyword ("color-mask"), &color_mask,
77 scm_from_utf8_keyword ("color-material"), &color_material,
78 scm_from_utf8_keyword ("blend-operation"), &blend_operation,
79 scm_from_utf8_keyword ("polygon-offset-factor"), &polygon_offset_factor,
80 scm_from_utf8_keyword ("polygon-offset-direction"), &polygon_offset_direction,
81 scm_from_utf8_keyword ("wireframe"), &wireframe,
82 scm_from_utf8_keyword ("point-cloud"), &point_cloud,
83 scm_from_utf8_keyword ("gouraud-shading"), &gouraud_shading,
84 scm_from_utf8_keyword ("lighting"), &lighting,
85 scm_from_utf8_keyword ("z-write-enable"), &z_write_enable,
86 scm_from_utf8_keyword ("backface-culling"), &backface_culling,
87 scm_from_utf8_keyword ("frontface-culling"), &frontface_culling,
88 scm_from_utf8_keyword ("fog-enable"), &fog_enable,
89 scm_from_utf8_keyword ("normalize-normals"), &normalize_normals,
90 scm_from_utf8_keyword ("use-mip-maps"), &use_mip_maps,
93 video::SMaterial* material = new video::SMaterial ();
94 material->MaterialType = scm_to_material_type(material_type);
95 material->AmbientColor = scm_to_color (ambient_color);
96 material->DiffuseColor = scm_to_color (diffuse_color);
97 material->EmissiveColor = scm_to_color (emissive_color);
98 material->SpecularColor = scm_to_color (specular_color);
99 material->Shininess = scm_to_double (shininess);
100 material->MaterialTypeParam = scm_to_double (material_type_param);
101 material->MaterialTypeParam2 = scm_to_double (material_type_param_2);
102 material->Thickness = scm_to_double (thickness);
103 material->ZBuffer = scm_to_comparison_func (z_buffer);
104 material->AntiAliasing = scm_to_anti_aliasing_mode (anti_aliasing);
105 material->ColorMask = scm_to_color_plane (color_mask);
106 material->ColorMaterial = scm_to_color_material (color_material);
107 material->BlendOperation = scm_to_blend_operation (blend_operation);
108 material->PolygonOffsetFactor = scm_to_uint8 (polygon_offset_factor);
109 material->PolygonOffsetDirection = scm_to_polygon_offset (polygon_offset_direction);
110 material->Wireframe = scm_to_bool (wireframe);
111 material->PointCloud = scm_to_bool (point_cloud);
112 material->GouraudShading = scm_to_bool (gouraud_shading);
113 material->Lighting = scm_to_bool (lighting);
114 material->ZWriteEnable = scm_to_bool (z_write_enable);
115 material->BackfaceCulling = scm_to_bool (backface_culling);
116 material->FrontfaceCulling = scm_to_bool (frontface_culling);
117 material->FogEnable = scm_to_bool (fog_enable);
118 material->NormalizeNormals = scm_to_bool (normalize_normals);
119 material->UseMipMaps = scm_to_bool (use_mip_maps);
120 return scm_from_irr_pointer ("<material>", (void*) material);
126 DEFINE_GSUBR ("SMaterial_make", 0, 0, 1, SMaterial_make);
129 video::E_ANTI_ALIASING_MODE
130 scm_to_anti_aliasing_mode (SCM anti_aliasing_mode)
132 char* mode_name = scm_to_utf8_string (scm_symbol_to_string (anti_aliasing_mode));
133 video::E_ANTI_ALIASING_MODE mode;
135 if (!strcmp (mode_name, "off"))
137 mode = video::EAAM_OFF;
139 else if (!strcmp (mode_name, "simple"))
141 mode = video::EAAM_SIMPLE;
143 else if (!strcmp (mode_name, "quality"))
145 mode = video::EAAM_QUALITY;
147 else if (!strcmp (mode_name, "line-smooth"))
149 mode = video::EAAM_LINE_SMOOTH;
151 else if (!strcmp (mode_name, "point-smooth"))
153 mode = video::EAAM_POINT_SMOOTH;
155 else if (!strcmp (mode_name, "full-basic"))
157 mode = video::EAAM_FULL_BASIC;
159 else if (!strcmp (mode_name, "alpha-to-coverage"))
161 mode = video::EAAM_ALPHA_TO_COVERAGE;
165 scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S",
166 scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode));
173 video::E_BLEND_OPERATION
174 scm_to_blend_operation (SCM blend_operation)
176 char* operation_name = scm_to_utf8_string (scm_symbol_to_string (blend_operation));
177 video::E_BLEND_OPERATION operation;
179 if (!strcmp (operation_name, "none"))
181 operation = video::EBO_NONE;
183 else if (!strcmp (operation_name, "add"))
185 operation = video::EBO_ADD;
187 else if (!strcmp (operation_name, "subtract"))
189 operation = video::EBO_SUBTRACT;
191 else if (!strcmp (operation_name, "rev-subtract"))
193 operation = video::EBO_REVSUBTRACT;
195 else if (!strcmp (operation_name, "min"))
197 operation = video::EBO_MIN;
199 else if (!strcmp (operation_name, "max"))
201 operation = video::EBO_MAX;
203 else if (!strcmp (operation_name, "min-factor"))
205 operation = video::EBO_MIN_FACTOR;
207 else if (!strcmp (operation_name, "max-factor"))
209 operation = video::EBO_MAX_FACTOR;
211 else if (!strcmp (operation_name, "min-alpha"))
213 operation = video::EBO_MIN_ALPHA;
215 else if (!strcmp (operation_name, "max-alpha"))
217 operation = video::EBO_MAX_ALPHA;
221 scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S",
222 scm_list_1 (blend_operation), scm_list_1 (blend_operation));
225 free (operation_name);
229 video::E_COLOR_MATERIAL
230 scm_to_color_material (SCM color_material)
232 char* material_name = scm_to_utf8_string (scm_symbol_to_string (color_material));
233 video::E_COLOR_MATERIAL material;
235 if (!strcmp (material_name, "none"))
237 material = video::ECM_NONE;
239 else if (!strcmp (material_name, "diffuse"))
241 material = video::ECM_DIFFUSE;
243 else if (!strcmp (material_name, "ambient"))
245 material = video::ECM_AMBIENT;
247 else if (!strcmp (material_name, "emissive"))
249 material = video::ECM_EMISSIVE;
251 else if (!strcmp (material_name, "specular"))
253 material = video::ECM_SPECULAR;
255 else if (!strcmp (material_name, "diffuse-and-ambient"))
257 material = video::ECM_DIFFUSE_AND_AMBIENT;
261 scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S",
262 scm_list_1 (color_material), scm_list_1 (color_material));
265 free (material_name);
270 scm_to_color_plane (SCM color_plane)
272 char* plane_name = scm_to_utf8_string (scm_symbol_to_string (color_plane));
273 video::E_COLOR_PLANE plane;
275 if (!strcmp (plane_name, "none"))
277 plane = video::ECP_NONE;
279 else if (!strcmp (plane_name, "alpha"))
281 plane = video::ECP_ALPHA;
283 else if (!strcmp (plane_name, "red"))
285 plane = video::ECP_RED;
287 else if (!strcmp (plane_name, "green"))
289 plane = video::ECP_GREEN;
291 else if (!strcmp (plane_name, "blue"))
293 plane = video::ECP_BLUE;
295 else if (!strcmp (plane_name, "rgb"))
297 plane = video::ECP_RGB;
299 else if (!strcmp (plane_name, "all"))
301 plane = video::ECP_ALL;
305 scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S",
306 scm_list_1 (color_plane), scm_list_1 (color_plane));
313 video::E_COMPARISON_FUNC
314 scm_to_comparison_func (SCM comparison_func)
316 char* func_name = scm_to_utf8_string (scm_symbol_to_string (comparison_func));
317 video::E_COMPARISON_FUNC func;
319 if (!strcmp (func_name, "never"))
321 func = video::ECFN_NEVER;
323 else if (!strcmp (func_name, "less-equal"))
325 func = video::ECFN_LESSEQUAL;
327 else if (!strcmp (func_name, "equal"))
329 func = video::ECFN_EQUAL;
331 else if (!strcmp (func_name, "less"))
333 func = video::ECFN_LESS;
335 else if (!strcmp (func_name, "not-equal"))
337 func = video::ECFN_NOTEQUAL;
339 else if (!strcmp (func_name, "greater-equal"))
341 func = video::ECFN_GREATEREQUAL;
343 else if (!strcmp (func_name, "greater"))
345 func = video::ECFN_GREATER;
347 else if (!strcmp (func_name, "always"))
349 func = video::ECFN_ALWAYS;
353 scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S",
354 scm_list_1 (comparison_func), scm_list_1 (comparison_func));
361 video::E_POLYGON_OFFSET
362 scm_to_polygon_offset (SCM polygon_offset)
364 char* offset_name = scm_to_utf8_string (scm_symbol_to_string (polygon_offset));
365 video::E_POLYGON_OFFSET offset;
367 if (!strcmp (offset_name, "back"))
369 offset = video::EPO_BACK;
371 else if (!strcmp (offset_name, "front"))
373 offset = video::EPO_FRONT;
377 scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S",
378 scm_list_1 (polygon_offset), scm_list_1 (polygon_offset));