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"
33 SMaterial_make (SCM rest)
41 SCM material_type_param;
42 SCM material_type_param_2;
49 SCM polygon_offset_factor;
50 SCM polygon_offset_direction;
57 SCM frontface_culling;
59 SCM normalize_normals;
62 scm_c_bind_keyword_arguments
63 ("video_SMaterial_make", rest, (scm_t_keyword_arguments_flags)0,
64 scm_from_utf8_keyword ("material-type"), &material_type,
65 scm_from_utf8_keyword ("ambient-color"), &ambient_color,
66 scm_from_utf8_keyword ("diffuse-color"), &diffuse_color,
67 scm_from_utf8_keyword ("emissive-color"), &emissive_color,
68 scm_from_utf8_keyword ("specular-color"), &specular_color,
69 scm_from_utf8_keyword ("shininess"), &shininess,
70 scm_from_utf8_keyword ("material-type-param"), &material_type_param,
71 scm_from_utf8_keyword ("material-type-param-2"), &material_type_param_2,
72 scm_from_utf8_keyword ("thickness"), &thickness,
73 scm_from_utf8_keyword ("z-buffer"), &z_buffer,
74 scm_from_utf8_keyword ("anti-aliasing"), &anti_aliasing,
75 scm_from_utf8_keyword ("color-mask"), &color_mask,
76 scm_from_utf8_keyword ("color-material"), &color_material,
77 scm_from_utf8_keyword ("blend-operation"), &blend_operation,
78 scm_from_utf8_keyword ("polygon-offset-factor"), &polygon_offset_factor,
79 scm_from_utf8_keyword ("polygon-offset-direction"), &polygon_offset_direction,
80 scm_from_utf8_keyword ("wireframe"), &wireframe,
81 scm_from_utf8_keyword ("point-cloud"), &point_cloud,
82 scm_from_utf8_keyword ("gouraud-shading"), &gouraud_shading,
83 scm_from_utf8_keyword ("lighting"), &lighting,
84 scm_from_utf8_keyword ("z-write-enable"), &z_write_enable,
85 scm_from_utf8_keyword ("backface-culling"), &backface_culling,
86 scm_from_utf8_keyword ("frontface-culling"), &frontface_culling,
87 scm_from_utf8_keyword ("fog-enable"), &fog_enable,
88 scm_from_utf8_keyword ("normalize-normals"), &normalize_normals,
89 scm_from_utf8_keyword ("use-mip-maps"), &use_mip_maps,
92 video::SMaterial* material = new video::SMaterial ();
93 material->MaterialType = scm_to_material_type(material_type);
94 material->AmbientColor = scm_to_color (ambient_color);
95 material->DiffuseColor = scm_to_color (diffuse_color);
96 material->EmissiveColor = scm_to_color (emissive_color);
97 material->SpecularColor = scm_to_color (specular_color);
98 material->Shininess = scm_to_double (shininess);
99 material->MaterialTypeParam = scm_to_double (material_type_param);
100 material->MaterialTypeParam2 = scm_to_double (material_type_param_2);
101 material->Thickness = scm_to_double (thickness);
102 material->ZBuffer = scm_to_comparison_func (z_buffer);
103 material->AntiAliasing = scm_to_anti_aliasing_mode (anti_aliasing);
104 material->ColorMask = scm_to_color_plane (color_mask);
105 material->ColorMaterial = scm_to_color_material (color_material);
106 material->BlendOperation = scm_to_blend_operation (blend_operation);
107 material->PolygonOffsetFactor = scm_to_uint8 (polygon_offset_factor);
108 material->PolygonOffsetDirection = scm_to_polygon_offset (polygon_offset_direction);
109 material->Wireframe = scm_to_bool (wireframe);
110 material->PointCloud = scm_to_bool (point_cloud);
111 material->GouraudShading = scm_to_bool (gouraud_shading);
112 material->Lighting = scm_to_bool (lighting);
113 material->ZWriteEnable = scm_to_bool (z_write_enable);
114 material->BackfaceCulling = scm_to_bool (backface_culling);
115 material->FrontfaceCulling = scm_to_bool (frontface_culling);
116 material->FogEnable = scm_to_bool (fog_enable);
117 material->NormalizeNormals = scm_to_bool (normalize_normals);
118 material->UseMipMaps = scm_to_bool (use_mip_maps);
119 return scm_from_pointer ((void*) material, NULL);
125 DEFINE_GSUBR ("SMaterial_make", 0, 0, 1, SMaterial_make);
128 video::E_ANTI_ALIASING_MODE
129 scm_to_anti_aliasing_mode (SCM anti_aliasing_mode)
131 char* mode_name = scm_to_utf8_string (scm_symbol_to_string (anti_aliasing_mode));
132 video::E_ANTI_ALIASING_MODE mode;
134 if (!strcmp (mode_name, "off"))
136 mode = video::EAAM_OFF;
138 else if (!strcmp (mode_name, "simple"))
140 mode = video::EAAM_SIMPLE;
142 else if (!strcmp (mode_name, "quality"))
144 mode = video::EAAM_QUALITY;
146 else if (!strcmp (mode_name, "line-smooth"))
148 mode = video::EAAM_LINE_SMOOTH;
150 else if (!strcmp (mode_name, "point-smooth"))
152 mode = video::EAAM_POINT_SMOOTH;
154 else if (!strcmp (mode_name, "full-basic"))
156 mode = video::EAAM_FULL_BASIC;
158 else if (!strcmp (mode_name, "alpha-to-coverage"))
160 mode = video::EAAM_ALPHA_TO_COVERAGE;
164 scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S",
165 scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode));
172 video::E_BLEND_OPERATION
173 scm_to_blend_operation (SCM blend_operation)
175 char* operation_name = scm_to_utf8_string (scm_symbol_to_string (blend_operation));
176 video::E_BLEND_OPERATION operation;
178 if (!strcmp (operation_name, "none"))
180 operation = video::EBO_NONE;
182 else if (!strcmp (operation_name, "add"))
184 operation = video::EBO_ADD;
186 else if (!strcmp (operation_name, "subtract"))
188 operation = video::EBO_SUBTRACT;
190 else if (!strcmp (operation_name, "rev-subtract"))
192 operation = video::EBO_REVSUBTRACT;
194 else if (!strcmp (operation_name, "min"))
196 operation = video::EBO_MIN;
198 else if (!strcmp (operation_name, "max"))
200 operation = video::EBO_MAX;
202 else if (!strcmp (operation_name, "min-factor"))
204 operation = video::EBO_MIN_FACTOR;
206 else if (!strcmp (operation_name, "max-factor"))
208 operation = video::EBO_MAX_FACTOR;
210 else if (!strcmp (operation_name, "min-alpha"))
212 operation = video::EBO_MIN_ALPHA;
214 else if (!strcmp (operation_name, "max-alpha"))
216 operation = video::EBO_MAX_ALPHA;
220 scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S",
221 scm_list_1 (blend_operation), scm_list_1 (blend_operation));
224 free (operation_name);
228 video::E_COLOR_MATERIAL
229 scm_to_color_material (SCM color_material)
231 char* material_name = scm_to_utf8_string (scm_symbol_to_string (color_material));
232 video::E_COLOR_MATERIAL material;
234 if (!strcmp (material_name, "none"))
236 material = video::ECM_NONE;
238 else if (!strcmp (material_name, "diffuse"))
240 material = video::ECM_DIFFUSE;
242 else if (!strcmp (material_name, "ambient"))
244 material = video::ECM_AMBIENT;
246 else if (!strcmp (material_name, "emissive"))
248 material = video::ECM_EMISSIVE;
250 else if (!strcmp (material_name, "specular"))
252 material = video::ECM_SPECULAR;
254 else if (!strcmp (material_name, "diffuse-and-ambient"))
256 material = video::ECM_DIFFUSE_AND_AMBIENT;
260 scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S",
261 scm_list_1 (color_material), scm_list_1 (color_material));
264 free (material_name);
269 scm_to_color_plane (SCM color_plane)
271 char* plane_name = scm_to_utf8_string (scm_symbol_to_string (color_plane));
272 video::E_COLOR_PLANE plane;
274 if (!strcmp (plane_name, "none"))
276 plane = video::ECP_NONE;
278 else if (!strcmp (plane_name, "alpha"))
280 plane = video::ECP_ALPHA;
282 else if (!strcmp (plane_name, "red"))
284 plane = video::ECP_RED;
286 else if (!strcmp (plane_name, "green"))
288 plane = video::ECP_GREEN;
290 else if (!strcmp (plane_name, "blue"))
292 plane = video::ECP_BLUE;
294 else if (!strcmp (plane_name, "rgb"))
296 plane = video::ECP_RGB;
298 else if (!strcmp (plane_name, "all"))
300 plane = video::ECP_ALL;
304 scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S",
305 scm_list_1 (color_plane), scm_list_1 (color_plane));
312 video::E_COMPARISON_FUNC
313 scm_to_comparison_func (SCM comparison_func)
315 char* func_name = scm_to_utf8_string (scm_symbol_to_string (comparison_func));
316 video::E_COMPARISON_FUNC func;
318 if (!strcmp (func_name, "never"))
320 func = video::ECFN_NEVER;
322 else if (!strcmp (func_name, "less-equal"))
324 func = video::ECFN_LESSEQUAL;
326 else if (!strcmp (func_name, "equal"))
328 func = video::ECFN_EQUAL;
330 else if (!strcmp (func_name, "less"))
332 func = video::ECFN_LESS;
334 else if (!strcmp (func_name, "not-equal"))
336 func = video::ECFN_NOTEQUAL;
338 else if (!strcmp (func_name, "greater-equal"))
340 func = video::ECFN_GREATEREQUAL;
342 else if (!strcmp (func_name, "greater"))
344 func = video::ECFN_GREATER;
346 else if (!strcmp (func_name, "always"))
348 func = video::ECFN_ALWAYS;
352 scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S",
353 scm_list_1 (comparison_func), scm_list_1 (comparison_func));
360 video::E_POLYGON_OFFSET
361 scm_to_polygon_offset (SCM polygon_offset)
363 char* offset_name = scm_to_utf8_string (scm_symbol_to_string (polygon_offset));
364 video::E_POLYGON_OFFSET offset;
366 if (!strcmp (offset_name, "back"))
368 offset = video::EPO_BACK;
370 else if (!strcmp (offset_name, "front"))
372 offset = video::EPO_FRONT;
376 scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S",
377 scm_list_1 (polygon_offset), scm_list_1 (polygon_offset));