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 video_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 ("video_SMaterial_make", 0, 0, 1, video_SMaterial_make);
128 video::E_ANTI_ALIASING_MODE
129 scm_to_anti_aliasing_mode (SCM anti_aliasing_mode)
131 char* mode = scm_to_utf8_string (scm_symbol_to_string (anti_aliasing_mode));
132 if (!strcmp (mode, "off"))
134 return video::EAAM_OFF;
136 else if (!strcmp (mode, "simple"))
138 return video::EAAM_SIMPLE;
140 else if (!strcmp (mode, "quality"))
142 return video::EAAM_QUALITY;
144 else if (!strcmp (mode, "line-smooth"))
146 return video::EAAM_LINE_SMOOTH;
148 else if (!strcmp (mode, "point-smooth"))
150 return video::EAAM_POINT_SMOOTH;
152 else if (!strcmp (mode, "full-basic"))
154 return video::EAAM_FULL_BASIC;
156 else if (!strcmp (mode, "alpha-to-coverage"))
158 return video::EAAM_ALPHA_TO_COVERAGE;
162 scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S",
163 scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode));
167 video::E_BLEND_OPERATION
168 scm_to_blend_operation (SCM blend_operation)
170 char* operation = scm_to_utf8_string (scm_symbol_to_string (blend_operation));
171 if (!strcmp (operation, "none"))
173 return video::EBO_NONE;
175 else if (!strcmp (operation, "add"))
177 return video::EBO_ADD;
179 else if (!strcmp (operation, "subtract"))
181 return video::EBO_SUBTRACT;
183 else if (!strcmp (operation, "rev-subtract"))
185 return video::EBO_REVSUBTRACT;
187 else if (!strcmp (operation, "min"))
189 return video::EBO_MIN;
191 else if (!strcmp (operation, "max"))
193 return video::EBO_MAX;
195 else if (!strcmp (operation, "min-factor"))
197 return video::EBO_MIN_FACTOR;
199 else if (!strcmp (operation, "max-factor"))
201 return video::EBO_MAX_FACTOR;
203 else if (!strcmp (operation, "min-alpha"))
205 return video::EBO_MIN_ALPHA;
207 else if (!strcmp (operation, "max-alpha"))
209 return video::EBO_MAX_ALPHA;
213 scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S",
214 scm_list_1 (blend_operation), scm_list_1 (blend_operation));
218 video::E_COLOR_MATERIAL
219 scm_to_color_material (SCM color_material)
221 char* material = scm_to_utf8_string (scm_symbol_to_string (color_material));
222 if (!strcmp (material, "none"))
224 return video::ECM_NONE;
226 else if (!strcmp (material, "diffuse"))
228 return video::ECM_DIFFUSE;
230 else if (!strcmp (material, "ambient"))
232 return video::ECM_AMBIENT;
234 else if (!strcmp (material, "emissive"))
236 return video::ECM_EMISSIVE;
238 else if (!strcmp (material, "specular"))
240 return video::ECM_SPECULAR;
242 else if (!strcmp (material, "diffuse-and-ambient"))
244 return video::ECM_DIFFUSE_AND_AMBIENT;
248 scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S",
249 scm_list_1 (color_material), scm_list_1 (color_material));
254 scm_to_color_plane (SCM color_plane)
256 char* plane = scm_to_utf8_string (scm_symbol_to_string (color_plane));
257 if (!strcmp (plane, "none"))
259 return video::ECP_NONE;
261 else if (!strcmp (plane, "alpha"))
263 return video::ECP_ALPHA;
265 else if (!strcmp (plane, "red"))
267 return video::ECP_RED;
269 else if (!strcmp (plane, "green"))
271 return video::ECP_GREEN;
273 else if (!strcmp (plane, "blue"))
275 return video::ECP_BLUE;
277 else if (!strcmp (plane, "rgb"))
279 return video::ECP_RGB;
281 else if (!strcmp (plane, "all"))
283 return video::ECP_ALL;
287 scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S",
288 scm_list_1 (color_plane), scm_list_1 (color_plane));
292 video::E_COMPARISON_FUNC
293 scm_to_comparison_func (SCM comparison_func)
295 char* func = scm_to_utf8_string (scm_symbol_to_string (comparison_func));
296 if (!strcmp (func, "never"))
298 return video::ECFN_NEVER;
300 else if (!strcmp (func, "less-equal"))
302 return video::ECFN_LESSEQUAL;
304 else if (!strcmp (func, "equal"))
306 return video::ECFN_EQUAL;
308 else if (!strcmp (func, "less"))
310 return video::ECFN_LESS;
312 else if (!strcmp (func, "not-equal"))
314 return video::ECFN_NOTEQUAL;
316 else if (!strcmp (func, "greater-equal"))
318 return video::ECFN_GREATEREQUAL;
320 else if (!strcmp (func, "greater"))
322 return video::ECFN_GREATER;
324 else if (!strcmp (func, "always"))
326 return video::ECFN_ALWAYS;
330 scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S",
331 scm_list_1 (comparison_func), scm_list_1 (comparison_func));
335 video::E_POLYGON_OFFSET
336 scm_to_polygon_offset (SCM polygon_offset)
338 char* offset = scm_to_utf8_string (scm_symbol_to_string (polygon_offset));
339 if (!strcmp (offset, "back"))
341 return video::EPO_BACK;
343 else if (!strcmp (offset, "front"))
345 return video::EPO_FRONT;
349 scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S",
350 scm_list_1 (polygon_offset), scm_list_1 (polygon_offset));