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"
35 video_SMaterial_make (SCM material_type, SCM ambient_color, SCM diffuse_color,
36 SCM emissive_color, SCM specular_color, SCM shininess,
37 SCM material_type_param, SCM material_type_param_2, SCM thickness,
38 SCM z_buffer, SCM anti_aliasing, SCM color_mask,
39 SCM color_material, SCM blend_operation, SCM polygon_offset_factor,
40 SCM polygon_offset_direction, SCM wireframe, SCM point_cloud,
41 SCM gouraud_shading, SCM lighting, SCM z_write_enable,
42 SCM backface_culling, SCM frontface_culling, SCM fog_enable,
43 SCM normalize_normals, SCM use_mip_maps)
45 video::SMaterial* material = new video::SMaterial ();
46 material->MaterialType = scm_to_material_type(material_type);
47 material->AmbientColor = scm_to_color (ambient_color);
48 material->DiffuseColor = scm_to_color (diffuse_color);
49 material->EmissiveColor = scm_to_color (emissive_color);
50 material->SpecularColor = scm_to_color (specular_color);
51 material->Shininess = scm_to_double (shininess);
52 material->MaterialTypeParam = scm_to_double (material_type_param);
53 material->MaterialTypeParam2 = scm_to_double (material_type_param_2);
54 material->Thickness = scm_to_double (thickness);
55 material->ZBuffer = scm_to_comparison_func (z_buffer);
56 material->AntiAliasing = scm_to_anti_aliasing_mode (anti_aliasing);
57 material->ColorMask = scm_to_color_plane (color_mask);
58 material->ColorMaterial = scm_to_color_material (color_material);
59 material->BlendOperation = scm_to_blend_operation (blend_operation);
60 material->PolygonOffsetFactor = scm_to_uint8 (polygon_offset_factor);
61 material->PolygonOffsetDirection = scm_to_polygon_offset (polygon_offset_direction);
62 material->Wireframe = scm_to_bool (wireframe);
63 material->PointCloud = scm_to_bool (point_cloud);
64 material->GouraudShading = scm_to_bool (gouraud_shading);
65 material->Lighting = scm_to_bool (lighting);
66 material->ZWriteEnable = scm_to_bool (z_write_enable);
67 material->BackfaceCulling = scm_to_bool (backface_culling);
68 material->FrontfaceCulling = scm_to_bool (frontface_culling);
69 material->FogEnable = scm_to_bool (fog_enable);
70 material->NormalizeNormals = scm_to_bool (normalize_normals);
71 material->UseMipMaps = scm_to_bool (use_mip_maps);
72 return scm_from_pointer ((void*) material, NULL);
81 DEFINE_GSUBR ("video_SMaterial_make", 26, 0, 0, video_SMaterial_make);
87 video::E_ANTI_ALIASING_MODE
88 scm_to_anti_aliasing_mode (SCM anti_aliasing_mode)
90 char* mode = scm_to_utf8_stringn (scm_symbol_to_string (anti_aliasing_mode), NULL);
91 if (!strcmp (mode, "off"))
93 return video::EAAM_OFF;
95 else if (!strcmp (mode, "simple"))
97 return video::EAAM_SIMPLE;
99 else if (!strcmp (mode, "quality"))
101 return video::EAAM_QUALITY;
103 else if (!strcmp (mode, "line-smooth"))
105 return video::EAAM_LINE_SMOOTH;
107 else if (!strcmp (mode, "point-smooth"))
109 return video::EAAM_POINT_SMOOTH;
111 else if (!strcmp (mode, "full-basic"))
113 return video::EAAM_FULL_BASIC;
115 else if (!strcmp (mode, "alpha-to-coverage"))
117 return video::EAAM_ALPHA_TO_COVERAGE;
121 scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S",
122 scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode));
127 video::E_BLEND_OPERATION
128 scm_to_blend_operation (SCM blend_operation)
130 char* operation = scm_to_utf8_stringn (scm_symbol_to_string (blend_operation), NULL);
131 if (!strcmp (operation, "none"))
133 return video::EBO_NONE;
135 else if (!strcmp (operation, "add"))
137 return video::EBO_ADD;
139 else if (!strcmp (operation, "subtract"))
141 return video::EBO_SUBTRACT;
143 else if (!strcmp (operation, "rev-subtract"))
145 return video::EBO_REVSUBTRACT;
147 else if (!strcmp (operation, "min"))
149 return video::EBO_MIN;
151 else if (!strcmp (operation, "max"))
153 return video::EBO_MAX;
155 else if (!strcmp (operation, "min-factor"))
157 return video::EBO_MIN_FACTOR;
159 else if (!strcmp (operation, "max-factor"))
161 return video::EBO_MAX_FACTOR;
163 else if (!strcmp (operation, "min-alpha"))
165 return video::EBO_MIN_ALPHA;
167 else if (!strcmp (operation, "max-alpha"))
169 return video::EBO_MAX_ALPHA;
173 scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S",
174 scm_list_1 (blend_operation), scm_list_1 (blend_operation));
179 video::E_COLOR_MATERIAL
180 scm_to_color_material (SCM color_material)
182 char* material = scm_to_utf8_stringn (scm_symbol_to_string (color_material), NULL);
183 if (!strcmp (material, "none"))
185 return video::ECM_NONE;
187 else if (!strcmp (material, "diffuse"))
189 return video::ECM_DIFFUSE;
191 else if (!strcmp (material, "ambient"))
193 return video::ECM_AMBIENT;
195 else if (!strcmp (material, "emissive"))
197 return video::ECM_EMISSIVE;
199 else if (!strcmp (material, "specular"))
201 return video::ECM_SPECULAR;
203 else if (!strcmp (material, "diffuse-and-ambient"))
205 return video::ECM_DIFFUSE_AND_AMBIENT;
209 scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S",
210 scm_list_1 (color_material), scm_list_1 (color_material));
216 scm_to_color_plane (SCM color_plane)
218 char* plane = scm_to_utf8_stringn (scm_symbol_to_string (color_plane), NULL);
219 if (!strcmp (plane, "none"))
221 return video::ECP_NONE;
223 else if (!strcmp (plane, "alpha"))
225 return video::ECP_ALPHA;
227 else if (!strcmp (plane, "red"))
229 return video::ECP_RED;
231 else if (!strcmp (plane, "green"))
233 return video::ECP_GREEN;
235 else if (!strcmp (plane, "blue"))
237 return video::ECP_BLUE;
239 else if (!strcmp (plane, "rgb"))
241 return video::ECP_RGB;
243 else if (!strcmp (plane, "all"))
245 return video::ECP_ALL;
249 scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S",
250 scm_list_1 (color_plane), scm_list_1 (color_plane));
255 video::E_COMPARISON_FUNC
256 scm_to_comparison_func (SCM comparison_func)
258 char* func = scm_to_utf8_stringn (scm_symbol_to_string (comparison_func), NULL);
259 if (!strcmp (func, "never"))
261 return video::ECFN_NEVER;
263 else if (!strcmp (func, "less-equal"))
265 return video::ECFN_LESSEQUAL;
267 else if (!strcmp (func, "equal"))
269 return video::ECFN_EQUAL;
271 else if (!strcmp (func, "less"))
273 return video::ECFN_LESS;
275 else if (!strcmp (func, "not-equal"))
277 return video::ECFN_NOTEQUAL;
279 else if (!strcmp (func, "greater-equal"))
281 return video::ECFN_GREATEREQUAL;
283 else if (!strcmp (func, "greater"))
285 return video::ECFN_GREATER;
287 else if (!strcmp (func, "always"))
289 return video::ECFN_ALWAYS;
293 scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S",
294 scm_list_1 (comparison_func), scm_list_1 (comparison_func));
299 video::E_POLYGON_OFFSET
300 scm_to_polygon_offset (SCM polygon_offset)
302 char* offset = scm_to_utf8_stringn (scm_symbol_to_string (polygon_offset), NULL);
303 if (!strcmp (offset, "back"))
305 return video::EPO_BACK;
307 else if (!strcmp (offset, "front"))
309 return video::EPO_FRONT;
313 scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S",
314 scm_list_1 (polygon_offset), scm_list_1 (polygon_offset));