atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_advance.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'w_advance.c'
24*
25* Contains:
26*
27
28 - The functions to create the OpenGL parameters edition window
29
30*
31* List of functions:
32
33 int * light_source_to_be_removed (int val, image * img, opengl_edition * ogl_edit);
34
35 G_MODULE_EXPORT gboolean scroll_scale_param (GtkRange * range, GtkScrollType scroll, gdouble value, gpointer data);
36 G_MODULE_EXPORT gboolean scroll_scale_quality (GtkRange * range, GtkScrollType scroll, gdouble value, gpointer data);
37 G_MODULE_EXPORT gboolean scroll_set_fog_param (GtkRange * range, GtkScrollType scroll, gdouble value, gpointer data);
38 G_MODULE_EXPORT gboolean close_advanced (GtkWidget * window, gpointer data);
39 G_MODULE_EXPORT gboolean close_advanced (GtkWidget * widg, GdkEvent * event, gpointer data);
40
41 void print_light_source (Light source, int i);
42 void show_active_light_data (opengl_edition * ogl_win, int lid, int tid);
43 void update_light_data (int li, opengl_edition * ogl_win);
44 void create_lights_combo (image * this_image, opengl_edition * ogl_win);
45 void add_remove_lights (int val, gpointer data);
46 void set_data_pos (vec3_t * vect, int pos, double v);
47 void param_has_changed (gpointer data, double val);
48 void fog_param_changed (gpointer data, GLfloat u, GtkRange * range);
49 void setup_fog_dialogs (glwin * view, int fid);
50 void close_advanced_opengl (gpointer data);
51
52 G_MODULE_EXPORT void toggled_delete_ligth (GtkCheckButton * but, gpointer data);
53 G_MODULE_EXPORT void toggled_delete_ligth (GtkToggleButton * but, gpointer data);
54 G_MODULE_EXPORT void run_light_source_to_be_removed (GtkDialog * win, gint response_id, gpointer data);
55 G_MODULE_EXPORT void show_light_param (GtkComboBox * box, gpointer data);
56 G_MODULE_EXPORT void set_nlights_spin (GtkSpinButton * res, gpointer data);
57 G_MODULE_EXPORT void set_nlights (GtkEntry * res, gpointer data);
58 G_MODULE_EXPORT void update_light_param (GtkEntry * res, gpointer data);
59 G_MODULE_EXPORT void set_object_pos (GtkEntry * res, gpointer data);
60 G_MODULE_EXPORT void set_light_type (GtkComboBox * box, gpointer data);
61 G_MODULE_EXPORT void set_light_fix (GtkComboBox * box, gpointer data);
62 G_MODULE_EXPORT void show_this_light (GtkCheckButton * but, gpointer data);
63 G_MODULE_EXPORT void show_this_light (GtkToggleButton * but, gpointer data);
64 G_MODULE_EXPORT void set_use_template_toggle (GtkCheckButton * but, gpointer data);
65 G_MODULE_EXPORT void set_use_template_toggle (GtkToggleButton * but, gpointer data);
66 G_MODULE_EXPORT void set_template (GtkComboBox * box, gpointer data);
67 G_MODULE_EXPORT void set_l_model (GtkComboBox * box, gpointer data);
68 G_MODULE_EXPORT void update_mat_param (GtkEntry * res, gpointer data);
69 G_MODULE_EXPORT void scale_param (GtkRange * range, gpointer data);
70 G_MODULE_EXPORT void scale_quality (GtkRange * range, gpointer data);
71 G_MODULE_EXPORT void set_fog_param (GtkRange * range, gpointer data);
72 G_MODULE_EXPORT void set_fog_type (GtkWidget * widg, gpointer data);
73 G_MODULE_EXPORT void set_fog_mode (GtkWidget * widg, gpointer data);
74 G_MODULE_EXPORT void opengl_advanced (GtkWidget * widg, gpointer data);
75
76 GtkWidget * adv_box (GtkWidget * box, char * lab, int size, float xalign);
77 GtkWidget * create_setting_pos (int pid, int lid, float * values, opengl_edition * ogl_win);
78 GtkWidget * lights_tab (glwin * view, opengl_edition * ogl_edit);
79 GtkWidget * materials_tab (glwin * view, opengl_edition * ogl_edit);
80 GtkWidget * fog_tab (glwin * view, opengl_edition * ogl_edit);
81
82 Light init_light_source (int type, float val, float vbl);
83 Light copy_light_source (Light old_sp);
84 Light * copy_light_sources (int dima, int dimb, Light * old_sp);
85
86*/
87
88#include "global.h"
89#include "interface.h"
90#include "glview.h"
91#include "glwindow.h"
92
93#define TEMPLATES 7
94
95extern void set_quality (int q, glwin * view);
96
97gchar * material_template[TEMPLATES] = {"Opaque",
98 "Brushed metal",
99 "Shiny metal",
100 "Plastic",
101 "Transparent",
102 "Translucent",
103 "Diffuse"};
104
105GLfloat template_parameters[TEMPLATES][5] ={{0.50, 0.50, 0.90, 1.00, 1.00}, // Ok
106 {0.90, 0.60, 1.00, 1.50, 1.00}, // Ok
107 {0.80, 0.40, 1.00, 1.00, 1.00}, // Ok
108 {0.35, 0.15, 1.00, 1.50, 1.00}, // Ok
109 {0.50, 0.50, 0.50, 1.00, 0.50}, //
110 {0.50, 0.50, 0.50, 1.00, 0.75}, //
111 {0.35, 0.80, 1.00, 1.50, 1.00}}; // Ok
112
113float mat_min_max[5][2] = {{0.0, 1.0},
114 {0.0, 1.0},
115 {0.0, 10.0},
116 {0.0, 10.0},
117 {0.0, 1.0}};
118
119gchar * settings[3][10] = {{"<u>Albedo:</u>",
120 "<u>Metallic:</u>",
121 "<u>Roughness:</u>",
122 "<u>Ambient occlusion:</u>",
123 "<u>Gamma correction:</u>",
124 "<u>Opacity:</u>"},
125 {"<u>Position:</u>",
126 "<u>Direction:</u>",
127 "<u>Intensity:</u>",
128 "<u>Constant attenuation:</u>",
129 "<u>Linear attenuation:</u>",
130 "<u>Quadratic attenuation:</u>",
131 "<u>Cone angle</u>",
132 "<u>Inner cutoff:</u>",
133 "<u>Outer cutoff:</u>"
134 "<u>Type:</u>"},
135 {"Color:"}};
136
137gchar * lpos[3] = {"x", "y", "z"};
138gchar * cpos[3] = {"r", "g", "b"};
139
150GtkWidget * adv_box (GtkWidget * box, char * lab, int size, float xalign)
151{
152 GtkWidget * hbox = create_hbox (0);
153 add_box_child_start (GTK_ORIENTATION_VERTICAL, box, hbox, TRUE, TRUE, 0);
154 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(lab, size, -1, xalign, 0.5), FALSE, FALSE, 5);
155 return hbox;
156
157}
158
159GtkWidget * d_close;
161
162#ifdef GTK4
171G_MODULE_EXPORT void toggled_delete_ligth (GtkCheckButton * but, gpointer data)
172{
173 if (gtk_check_button_get_active (but))
174#else
183G_MODULE_EXPORT void toggled_delete_ligth (GtkToggleButton * but, gpointer data)
184{
185 if (gtk_toggle_button_get_active (but))
186#endif
187 {
188 status --;
189 }
190 else
191 {
192 status ++;
193 }
194 if (status == 0)
195 {
197 }
198 else
199 {
201 }
202}
203
205GtkWidget ** light_but;
206
216G_MODULE_EXPORT void run_light_source_to_be_removed (GtkDialog * win, gint response_id, gpointer data)
217{
218 image * img = (image *)data;
219 int i, j;
220 j = 0;
221 for (i=0; i<img -> lights; i++)
222 {
223#ifdef GTK4
224 if (gtk_check_button_get_active (GTK_CHECK_BUTTON(light_but[i])))
225#else
226 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(light_but[i])))
227#endif
228 {
229 light_list[j] = i;
230 j ++;
231 }
232 }
234}
235
246{
247 int i;
248 gchar * str;
249 status = val;
250 GtkWidget * win = dialogmodal ("Remove light source(s)", GTK_WINDOW(ogl_edit -> win));
251 GtkWidget * vbox = dialog_get_content_area (win);
252 d_close = gtk_dialog_get_widget_for_response (GTK_DIALOG (win), GTK_RESPONSE_CLOSE);
254 if (val > 1)
255 {
256 str = g_strdup_printf ("Please select the %d light sources to be removed: ", val);
257 }
258 else
259 {
260 str = g_strdup_printf ("Please select the %d light source to be removed: ", val);
261 }
262 bbox (vbox, str);
263 g_free (str);
264 light_but = g_malloc (img -> lights * sizeof*light_but);
265 for (i=0; i<img -> lights; i++)
266 {
267 str = g_strdup_printf ("Light N°%d", i+1);
268 light_but[i] = check_button (str, -1, 40, FALSE, G_CALLBACK(toggled_delete_ligth), (gpointer)GINT_TO_POINTER(i));
269 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, light_but[i], TRUE, TRUE, 0);
270 g_free (str);
271 }
274 return light_list;
275}
276
285void print_light_source (Light source, int i)
286{
287 g_debug ("\n");
288 g_debug ("Light N°%d", i);
289 g_debug ("Type= %d", source.type);
290 g_debug ("Pos_x= %f, Pos_y= %f, Pos_z= %f", source.position.x, source.position.y, source.position.z);
291 g_debug ("Dir_x= %f, Dir_y= %f, Dir_z= %f", source.direction.x, source.direction.y, source.direction.z);
292 g_debug ("Int_r= %f, Int_g= %f, Int_b= %f", source.intensity.x, source.intensity.y, source.intensity.z);
293 g_debug ("Att_c= %f, Att_l= %f, Att_q= %f", source.attenuation.x, source.attenuation.y, source.attenuation.z);
294 g_debug ("Spo_a= %f, Spo_i= %f, Spo_o= %f", source.spot_data.x, source.spot_data.y, source.spot_data.z);
295 g_debug ("\n");
296}
297
298/*
299 Light attenuation table (from Ogre3D):
300 Distance(to object) Constant Linear Quadratic
301 7 1.0 0.7 1.8
302 13 1.0 0.35 0.44
303 20 1.0 0.22 0.20
304 32 1.0 0.14 0.07
305 50 1.0 0.09 0.032
306 65 1.0 0.07 0.017
307 100 1.0 0.045 0.0075
308 160 1.0 0.027 0.0028
309 200 1.0 0.022 0.0019
310 325 1.0 0.014 0.0007
311 600 1.0 0.007 0.0002
312 3250 1.0 0.0014 0.000007
313*/
314
324Light init_light_source (int type, float val, float vbl)
325{
326 Light new_light;
327 new_light.type = type;
328 new_light.fix = (type != 1) ? 0 : 1;
329 new_light.show = 0;
330 new_light.direction = vec3(0.0, 0.0, 0.0);
331 double intensity = (type == 1) ? 100.0*DEFAULT_INTENSITY : DEFAULT_INTENSITY;
332 // double intensity = DEFAULT_INTENSITY;
333 if (val != vbl)
334 {
335 intensity *= exp (val/vbl);
336 }
337 if (vbl <= 50.0) intensity *= vbl / 100.0;
338
339 new_light.intensity = vec3 (intensity, intensity, intensity);
340 new_light.attenuation = vec3 (1.0, 0.14, 0.07);
341 new_light.spot_data = vec3 (20.0, 20.0, 20.0);
342 if (type == 0)
343 {
344 new_light.position = vec3 (0.0, 0.0, 0.0);
345 new_light.direction = vec3 (0.0, 0.0, -1.0);
346 }
347 else
348 {
349 new_light.position = vec3 (vbl*1.5, 0.0, 0.0);
350 if (type == 2)
351 {
352 new_light.intensity = v3_muls (new_light.intensity, 100.0);
353 float tan = (val * sqrt(2.0) / 2.0) / (vbl - val);
354 float tetha = fabs(atanf (tan)) * 90.0 / pi;
355 new_light.spot_data = vec3 (tetha, tetha, tetha);
356 }
357 }
358 return new_light;
359}
360
369{
370 Light new_sp;
371 new_sp.type = old_sp.type;
372 new_sp.fix = old_sp.fix;
373 new_sp.show = old_sp.show;
374 new_sp.position = old_sp.position;
375 new_sp.direction = old_sp.direction;
376 new_sp.intensity = old_sp.intensity;
377 new_sp.attenuation = old_sp.attenuation;
378 new_sp.spot_data = old_sp.spot_data;
379 return new_sp;
380}
381
391Light * copy_light_sources (int dima, int dimb, Light * old_sp)
392{
393 int j;
394 Light * new_sp = g_malloc (dima*sizeof * new_sp);
395 for (j=0; j<dimb; j++)
396 {
397 //print_light_source (old_sp[j], j);
398 new_sp[j] = copy_light_source (old_sp[j]);
399 /*new_sp[j].type = old_sp[j].type;
400 new_sp[j].fix = old_sp[j].fix;
401 new_sp[j].show = old_sp[j].show;
402 new_sp[j].position = old_sp[j].position;
403 new_sp[j].direction = old_sp[j].direction;
404 new_sp[j].intensity = old_sp[j].intensity;
405 new_sp[j].attenuation = old_sp[j].attenuation;
406 new_sp[j].spot_data = old_sp[j].spot_data;*/
407 //print_light_source (new_sp[j], j);
408 }
409 return new_sp;
410}
411
421void show_active_light_data (opengl_edition * ogl_win, int lid, int tid)
422{
423 Light * this_light = & get_project_by_id(ogl_win -> proj) -> modelgl -> anim -> last -> img -> l_ght[lid];
424 this_light -> type = tid;
425 int i;
426 for (i=0; i<2; i++)
427 {
428 if (is_the_widget_visible(ogl_win -> light_b_coord[i])) hide_the_widgets (ogl_win -> light_b_coord[i]);
429 if (is_the_widget_visible(ogl_win -> light_b_entry[i])) hide_the_widgets (ogl_win -> light_b_entry[i]);
430 if ((i == 0 && this_light -> type != 0) || (i == 1 && this_light -> type != 1))
431 {
432 show_the_widgets (ogl_win -> light_b_coord[i]);
433 }
434 }
435 if (this_light -> type > 0) show_the_widgets (ogl_win -> light_b_entry[0]);
436 if (this_light -> type > 1) show_the_widgets (ogl_win -> light_b_entry[1]);
437
438 if (is_the_widget_visible(ogl_win -> light_show)) hide_the_widgets (ogl_win -> light_show);
439 if (is_the_widget_visible(ogl_win -> advanced_light_box)) hide_the_widgets (ogl_win -> advanced_light_box);
440 widget_set_sensitive (ogl_win -> light_type, lid);
441 if (this_light -> type != 0)
442 {
443 show_the_widgets (ogl_win -> advanced_light_box);
444 show_the_widgets (ogl_win -> light_show);
445 }
446}
447
456void update_light_data (int li, opengl_edition * ogl_win)
457{
458 Light * this_light = & get_project_by_id(ogl_win -> proj) -> modelgl -> anim -> last -> img -> l_ght[li];
459 gtk_combo_box_set_active (GTK_COMBO_BOX(ogl_win -> light_type), this_light -> type);
460 gtk_combo_box_set_active (GTK_COMBO_BOX(ogl_win -> light_fix), this_light -> fix);
461 show_active_light_data (ogl_win, li, this_light -> type);
462 update_entry_double (GTK_ENTRY(ogl_win -> light_entry[0]), this_light -> attenuation.x);
463 update_entry_double (GTK_ENTRY(ogl_win -> light_entry[1]), this_light -> attenuation.y);
464 update_entry_double (GTK_ENTRY(ogl_win -> light_entry[2]), this_light -> attenuation.z);
465 update_entry_double (GTK_ENTRY(ogl_win -> light_entry[3]), this_light -> spot_data.x);
466 update_entry_double (GTK_ENTRY(ogl_win -> light_entry[4]), this_light -> spot_data.y);
467 update_entry_double (GTK_ENTRY(ogl_win -> light_entry[5]), this_light -> spot_data.z);
468 update_entry_double (GTK_ENTRY(ogl_win -> entogl[1][0]), this_light -> position.x);
469 update_entry_double (GTK_ENTRY(ogl_win -> entogl[1][1]), this_light -> position.y);
470 update_entry_double (GTK_ENTRY(ogl_win -> entogl[1][2]), this_light -> position.z);
471 update_entry_double (GTK_ENTRY(ogl_win -> entogl[2][0]), this_light -> direction.x);
472 update_entry_double (GTK_ENTRY(ogl_win -> entogl[2][1]), this_light -> direction.y);
473 update_entry_double (GTK_ENTRY(ogl_win -> entogl[2][2]), this_light -> direction.z);
474 update_entry_double (GTK_ENTRY(ogl_win -> entogl[3][0]), this_light -> intensity.x);
475 update_entry_double (GTK_ENTRY(ogl_win -> entogl[3][1]), this_light -> intensity.y);
476 update_entry_double (GTK_ENTRY(ogl_win -> entogl[3][2]), this_light -> intensity.z);
477#ifdef GTK4
478 gtk_check_button_set_active (GTK_CHECK_BUTTON(ogl_win -> light_show), this_light -> show);
479#else
480 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(ogl_win -> light_show), this_light -> show);
481#endif
482}
483
492G_MODULE_EXPORT void show_light_param (GtkComboBox * box, gpointer data)
493{
494 int li = gtk_combo_box_get_active (box);
495 update_light_data (li, (opengl_edition *)data);
496}
497
506void create_lights_combo (image * this_image, opengl_edition * ogl_win)
507{
508 ogl_win -> lights = create_combo ();
509 int i;
510 gchar * str;
511 for (i=0; i<this_image -> lights; i++)
512 {
513 str = g_strdup_printf ("Light N°%d", i+1);
514 combo_text_append (ogl_win -> lights, str);
515 g_free (str);
516 }
517 gtk_widget_set_size_request (ogl_win -> lights, 100, -1);
518 g_signal_connect (G_OBJECT (ogl_win -> lights), "changed", G_CALLBACK(show_light_param), ogl_win);
519 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, ogl_win -> lights_box, ogl_win -> lights, FALSE, FALSE, 10);
520}
521
530void add_remove_lights (int val, gpointer data)
531{
532 int i, j, k, m;
533 glwin * view = (glwin *)data;
534 project * this_proj = get_project_by_id(view -> proj);
535 image * this_image = view -> anim -> last -> img;
536 gboolean delete_ligth;
537 i = this_image -> lights;
538 Light * old_spots;
539 if (val > i)
540 {
541#ifdef DEBUG
542 g_debug ("ADDING_LIGHT_SOURCE:: val= %d, i= %d", val, i);
543#endif
544 // Adding light source(s)
545 old_spots = copy_light_sources (i, i, this_image -> l_ght);
546 g_free (this_image -> l_ght);
547 this_image -> l_ght = copy_light_sources (val, i, old_spots);
548 this_image -> lights = val;
549 float pos = (this_proj -> cell.box[0].param[0][0] == 0.0) ? 20.0 : this_proj -> cell.box[0].param[0][0];
550 for (j=i; j<val; j++)
551 {
552 this_image -> l_ght[j] = init_light_source (0, pos, this_proj -> modelgl -> p_moy); // Init directional by default
553 }
554 //free (old_spots);
555 }
556 else if (val < i)
557 {
558 // We need to remove a light
559#ifdef DEBUG
560 g_debug ("REMOVING_LIGHT_SOURCE:: val= %d, i= %d", val, i);
561#endif
562 int * ltr = light_source_to_be_removed (i-val, this_image, view -> opengl_win);
563 if (ltr != NULL)
564 {
565 old_spots = copy_light_sources (i, i, this_image -> l_ght);
566 for (k=0; k < i-val; k++)
567 {
568#ifdef DEBUG
569 g_debug ("REMOVING_LIGHT_SOURCES:: k= %d, ltr[%d]= %d", k, k, ltr[k]);
570#endif
571 }
572 g_free (this_image -> l_ght);
573 this_image -> l_ght = g_malloc (val*sizeof*this_image -> l_ght);
574 m = -1;
575 for (j=0; j<i; j++)
576 {
577 delete_ligth = FALSE;
578 for (k=0; k< i-val; k++)
579 {
580 if (j == ltr[k]) delete_ligth = TRUE;
581 }
582 if (! delete_ligth)
583 {
584 m ++;
585 this_image -> l_ght[m] = copy_light_source (old_spots[j]);
586 }
587 }
588 g_free (old_spots);
589 this_image -> lights = val;
590#ifdef DEBUG
591 g_debug ("LIGHT(s) HAVE BEEN REMOVED:: NEW_LIGHTS_NUM= %d", val);
592#endif
593 }
594 }
595 //this_light = this_image -> l_ght;
596 view -> create_shaders[LIGHT] = TRUE;
597 view -> opengl_win -> lights = destroy_this_widget (view -> opengl_win -> lights);
598 create_lights_combo (this_image, view -> opengl_win);
599 show_the_widgets (view -> opengl_win -> lights);
600 gtk_combo_box_set_active (GTK_COMBO_BOX(view -> opengl_win -> lights), 0);
601 update_light_data (0, view -> opengl_win);
602 update (view);
603}
604
613G_MODULE_EXPORT void set_nlights_spin (GtkSpinButton * res, gpointer data)
614{
615 add_remove_lights (gtk_spin_button_get_value_as_int(res), data);
616}
617
626G_MODULE_EXPORT void set_nlights (GtkEntry * res, gpointer data)
627{
628 int i;
629 const gchar * m;
630 m = entry_get_text (res);
631 i = (int) string_to_double ((gpointer)m);
632 add_remove_lights (i, data);
633}
634
643G_MODULE_EXPORT void update_light_param (GtkEntry * res, gpointer data)
644{
645 dint * lid = (dint *)data;
646 glwin * view = get_project_by_id(lid -> a) -> modelgl;
647 if (view -> opengl_win)
648 {
649 int li = gtk_combo_box_get_active (GTK_COMBO_BOX(view -> opengl_win -> lights));
650 Light * this_light = & view -> anim -> last -> img -> l_ght[li];
651 const gchar * m = entry_get_text (res);
652 double v = string_to_double ((gpointer)m);
653 switch (lid -> b)
654 {
655 case 0:
656 this_light -> attenuation.x = v;
657 break;
658 case 1:
659 this_light -> attenuation.y = v;
660 break;
661 case 2:
662 this_light -> attenuation.z = v;
663 break;
664 case 3:
665 this_light -> spot_data.x = v;
666 break;
667 case 4:
668 this_light -> spot_data.y = v;
669 break;
670 case 5:
671 this_light -> spot_data.z = v;
672 break;
673 }
675 if (this_light -> show) view -> create_shaders[LIGHT] = TRUE;
676 }
677 update (view);
678}
679
689void set_data_pos (vec3_t * vect, int pos, double v)
690{
691 switch (pos)
692 {
693 case 0:
694 vect -> x = v;
695 break;
696 case 1:
697 vect -> y = v;
698 break;
699 case 2:
700 vect -> z = v;
701 break;
702 }
703}
704
713G_MODULE_EXPORT void set_object_pos (GtkEntry * res, gpointer data)
714{
715 tint * id = (tint *)data;
716 const gchar * m = entry_get_text (res);
717 double v = string_to_double ((gpointer)m);
718 glwin * view = get_project_by_id(id -> a) -> modelgl;
719 image * this_image = view -> anim -> last -> img;
720 if (id -> b == 0)
721 {
722 set_data_pos (& this_image -> m_terial.albedo, id -> c, v);
723 }
724 else if (id -> b == 4)
725 {
726 set_data_pos (& this_image -> f_g.color, id -> c, v);
727 }
728 else if (id -> b > 0 && view -> opengl_win)
729 {
730 int li = gtk_combo_box_get_active (GTK_COMBO_BOX(view -> opengl_win -> lights));
731 switch (id -> b)
732 {
733 case 1:
734 set_data_pos (& this_image -> l_ght[li].position, id -> c, v);
735 break;
736 case 2:
737 set_data_pos (& this_image -> l_ght[li].direction, id -> c, v);
738 break;
739 case 3:
740 set_data_pos (& this_image -> l_ght[li].intensity, id -> c, v);
741 break;
742 }
743 if (this_image -> l_ght[li].show) view -> create_shaders[LIGHT] = TRUE;
744 }
745 if (view -> opengl_win) update_entry_double (res, v);
746 update (view);
747}
748
757G_MODULE_EXPORT void set_light_type (GtkComboBox * box, gpointer data)
758{
759 opengl_edition * ogl_win = (opengl_edition *)data;
760 int li = gtk_combo_box_get_active (GTK_COMBO_BOX(ogl_win -> lights));
761 int ti = gtk_combo_box_get_active (box);
762 show_active_light_data (ogl_win, li, ti);
763}
764
773G_MODULE_EXPORT void set_light_fix (GtkComboBox * box, gpointer data)
774{
775 opengl_edition * ogl_win = (opengl_edition *)data;
776 glwin * view = get_project_by_id(ogl_win -> proj) -> modelgl;
777 int li = gtk_combo_box_get_active (GTK_COMBO_BOX(ogl_win -> lights));
778 view -> anim -> last -> img -> l_ght[li].fix = gtk_combo_box_get_active (box);
779 view -> create_shaders[LIGHT] = TRUE;
780 update (view);
781}
782
783#ifdef GTK4
792G_MODULE_EXPORT void show_this_light (GtkCheckButton * but, gpointer data)
793#else
802G_MODULE_EXPORT void show_this_light (GtkToggleButton * but, gpointer data)
803#endif
804{
805 opengl_edition * ogl_win = (opengl_edition *)data;
806 glwin * view = get_project_by_id(ogl_win -> proj) -> modelgl;
807 int li = gtk_combo_box_get_active (GTK_COMBO_BOX(ogl_win -> lights));
808#ifdef GTK4
809 view -> anim -> last -> img -> l_ght[li].show = gtk_check_button_get_active (but);
810#else
811 view -> anim -> last -> img -> l_ght[li].show = gtk_toggle_button_get_active (but);
812#endif
813 view -> create_shaders[LIGHT] = TRUE;
814 update (view);
815}
816
827GtkWidget * create_setting_pos (int pid, int lid, float * values, opengl_edition * ogl_win)
828{
829 int i;
830 GtkWidget * setting_pos = create_vbox (5);
831 if (pid != 0) abox (setting_pos, settings[(pid < 4) ? 1 : 2][lid], 0);
832 GtkWidget * box = create_hbox (0);
833 add_box_child_start (GTK_ORIENTATION_VERTICAL, setting_pos, box, FALSE, FALSE, 0);
834
835 for (i=0; i<3; i++)
836 {
837 ogl_win -> pos_pointer[pid][i].a = ogl_win -> proj;
838 ogl_win -> pos_pointer[pid][i].b = pid;
839 ogl_win -> pos_pointer[pid][i].c = i;
840 if (pid > 0 && pid < 3)
841 {
842 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, gtk_label_new (lpos[i]), FALSE, FALSE, 20);
843 }
844 else
845 {
846 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, gtk_label_new (cpos[i]), FALSE, FALSE, 20);
847 }
848 ogl_win -> entogl[pid][i] = create_entry (G_CALLBACK(set_object_pos), 80, 10, FALSE, & ogl_win -> pos_pointer[pid][i]);
849 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, ogl_win -> entogl[pid][i], FALSE, FALSE, 0);
850 update_entry_double (GTK_ENTRY(ogl_win -> entogl[pid][i]), values[i]);
851 }
852 if (pid == 1)
853 {
854 ogl_win -> light_show = check_button ("Show light", -1, -1, FALSE, G_CALLBACK(show_this_light), ogl_win);
855 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, ogl_win -> light_show, FALSE, FALSE, 15);
856 }
857 return setting_pos;
858}
859
868GtkWidget * lights_tab (glwin * view, opengl_edition * ogl_edit)
869{
870 int i, j, k;
871 image * this_image = view -> anim -> last -> img;
872 GtkWidget * vbox;
873 GtkWidget * hbox, * lhbox;
874
875 GtkWidget * layout = create_layout (-1, 300);
876 vbox = add_vbox_to_layout (layout, 480, -1);
877
878 GtkWidget * box = abox (vbox, "Number of light sources:\n(add or remove lights - up to 10 sources)", 10);
879 gtk_widget_set_size_request (box, -1, 65);
880
881 GtkWidget * nlights = spin_button (G_CALLBACK(set_nlights_spin), this_image -> lights, 1.0, 10.0, 1.0, 0, 100, view);
882 gtk_widget_set_size_request (nlights, 25, -1);
883 GtkWidget * fix = gtk_fixed_new ();
884 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, fix, FALSE, FALSE, 20);
885 gtk_fixed_put (GTK_FIXED (fix), nlights, 0, 10);
886 box = abox (vbox, "Configure light source:", 0);
887 ogl_edit -> lights_box = create_hbox (0);
888 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, ogl_edit -> lights_box, FALSE, FALSE, 10);
889 create_lights_combo (this_image, ogl_edit);
890
891 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, gtk_label_new ("Note: it is mandatory for light N°1 to be a directional light"), FALSE, FALSE, 10);
892
893 box = abox (vbox, "Light configuration: ", 0);
894
895 hbox = adv_box (vbox, settings[1][9], 170, 0.0);
896 ogl_edit -> light_type = create_combo ();
897 gchar * ltype[3] = {"Directional", "Point", "Spot"};
898 for (i=0; i<3; i++)
899 {
900 combo_text_append (ogl_edit -> light_type, ltype[i]);
901 }
902 g_signal_connect (G_OBJECT (ogl_edit -> light_type), "changed", G_CALLBACK(set_light_type), ogl_edit);
903 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ogl_edit -> light_type, FALSE, FALSE, 10);
904
905 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, gtk_label_new("Fixed by respect to: "), FALSE, FALSE, 10);
906 ogl_edit -> light_fix = create_combo();
907 gchar * lfix[2] = {"The viewer", "The model"};
908 for (i=0; i<2; i++)
909 {
910 combo_text_append (ogl_edit -> light_fix, lfix[i]);
911 }
912 g_signal_connect (G_OBJECT (ogl_edit -> light_fix), "changed", G_CALLBACK(set_light_fix), ogl_edit);
913 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ogl_edit -> light_fix, FALSE, FALSE, 10);
914
915 float values[3] = {0.0, 0.0, 0.0};
916 // Direction
917 ogl_edit -> light_b_coord[0] = create_setting_pos (1, 0, values, ogl_edit);
918 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, ogl_edit -> light_b_coord[0], FALSE, FALSE, 0);
919 // Position
920 ogl_edit -> light_b_coord[1] = create_setting_pos (2, 1, values, ogl_edit);
921 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, ogl_edit -> light_b_coord[1], FALSE, FALSE, 0);
922 // Intensity
923 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, create_setting_pos (3, 2, values, ogl_edit), FALSE, FALSE, 0);
924 ogl_edit -> advanced_light_box = create_vbox (BSEP);
925 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, ogl_edit -> advanced_light_box, FALSE, FALSE, 5);
926 add_box_child_start (GTK_ORIENTATION_VERTICAL, ogl_edit -> advanced_light_box, markup_label("<b>Advanced parameters:</b>", -1, -1, 0.1, 0.65), FALSE, FALSE, 25);
927 hbox = create_hbox (0);
928 add_box_child_start (GTK_ORIENTATION_VERTICAL, ogl_edit -> advanced_light_box, hbox, FALSE, FALSE, 0);
929 k = 0;
930 for (i=0; i<2; i++)
931 {
932 ogl_edit -> light_b_entry[i] = create_vbox (BSEP);
933 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ogl_edit -> light_b_entry[i], FALSE, FALSE, 0);
934 for (j=0; j<3; j++)
935 {
936 ogl_edit -> light_entry[k] = create_entry (G_CALLBACK(update_light_param), 100, 15, FALSE, &ogl_edit -> pointer[k]);
937 lhbox = adv_box (ogl_edit -> light_b_entry[i], settings[1][k+3], 170, 0.0);
938 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, lhbox, ogl_edit -> light_entry[k], FALSE, FALSE, 10);
939 if (i == 1) add_box_child_start (GTK_ORIENTATION_HORIZONTAL, lhbox, gtk_label_new("°"), FALSE, FALSE, 5);
940 k ++;
941 }
942 }
944 gtk_combo_box_set_active (GTK_COMBO_BOX(ogl_edit -> lights), 0);
945 return layout;
946}
947
948// ***************** MATERIAL ******************* //
949
950#ifdef GTK4
959G_MODULE_EXPORT void set_use_template_toggle (GtkCheckButton * but, gpointer data)
960#else
969G_MODULE_EXPORT void set_use_template_toggle (GtkToggleButton * but, gpointer data)
970#endif
971{
972 int i, j, k;
973 glwin * view = (glwin *)data;
974 i = gtk_combo_box_get_active (GTK_COMBO_BOX(view -> opengl_win -> templates));
975#ifdef GTK4
976 j = gtk_check_button_get_active (but);
977#else
978 j = gtk_toggle_button_get_active (but);
979#endif
980 if (j)
981 {
982 if (i == -1) i = 3;
983 for (k=0; k<5; k++) view -> anim -> last -> img -> m_terial.param[k+1] = template_parameters[i][k];
984 gtk_combo_box_set_active (GTK_COMBO_BOX(view -> opengl_win -> templates), i);
985 k = i+1;
986 }
987 else
988 {
989 k = 0;
990 }
991 view -> anim -> last -> img -> m_terial.predefine = k;
992 widget_set_sensitive (view -> opengl_win -> templates, view -> anim -> last -> img -> m_terial.predefine);
993 widget_set_sensitive (view -> opengl_win -> param_mat, ! view -> anim -> last -> img -> m_terial.predefine);
994 update (view);
995}
996
1005G_MODULE_EXPORT void set_template (GtkComboBox * box, gpointer data)
1006{
1007 int i, j;
1008 glwin * view = (glwin *)data;
1009 Material * mat = & view -> anim -> last -> img -> m_terial;
1010 i = gtk_combo_box_get_active (box);
1011 //gtk_range_set_value (GTK_RANGE(shiny), template_parameters[i][0]);
1012 for (j=0; j<5; j++)
1013 {
1014#ifdef DEBUG
1015 g_debug ("SET_TEMPLATES:: j= %d, val= %f", j, template_parameters[i][j]);
1016#endif
1017 //gtk_range_set_value (GTK_RANGE(base_ogl[0][j]), template_parameters[i][j+1]);
1018 }
1019 mat -> predefine = i + 1;
1020 for (j=0; j<5; j++) mat -> param[j+1] = template_parameters[i][j];
1021 update (view);
1022}
1023
1032G_MODULE_EXPORT void set_l_model (GtkComboBox * box, gpointer data)
1033{
1034 glwin * view = (glwin *)data;
1035 view -> anim -> last -> img -> m_terial.param[0] = gtk_combo_box_get_active (box);
1036 update (view);
1037}
1038
1047void param_has_changed (gpointer data, double val)
1048{
1049 dint * mid = (dint *)data;
1050 glwin * view = get_project_by_id(mid -> a) -> modelgl;
1051 Material * mat = & view -> anim -> last -> img -> m_terial;
1052 if (mat_min_max[mid -> b][0] >= 0.0 && val <= mat_min_max[mid -> b][1]) mat -> param[mid -> b + 1] = val;
1053 if (view -> opengl_win)
1054 {
1055 update_entry_double (GTK_ENTRY(view -> opengl_win -> m_entry[mid -> b]), mat -> param[mid -> b + 1]);
1056 gtk_range_set_value (GTK_RANGE(view -> opengl_win -> m_scale[mid -> b]), mat -> param[mid -> b + 1]);
1057 }
1058 update (view);
1059}
1060
1069G_MODULE_EXPORT void update_mat_param (GtkEntry * res, gpointer data)
1070{
1071 const gchar * m = entry_get_text (res);
1072 double v = string_to_double ((gpointer)m);
1073 param_has_changed (data, v);
1074}
1075
1086G_MODULE_EXPORT gboolean scroll_scale_param (GtkRange * range, GtkScrollType scroll, gdouble value, gpointer data)
1087{
1088 param_has_changed (data, value);
1089 return FALSE;
1090}
1091
1100G_MODULE_EXPORT void scale_param (GtkRange * range, gpointer data)
1101{
1102 param_has_changed (data, gtk_range_get_value (range));
1103}
1104
1115G_MODULE_EXPORT gboolean scroll_scale_quality (GtkRange * range, GtkScrollType scroll, gdouble value, gpointer data)
1116{
1117 set_quality ((int)value, data);
1118#ifdef GTK4
1119 update_menu_bar ((glwin *)data);
1120#endif
1121 return FALSE;
1122}
1123
1132G_MODULE_EXPORT void scale_quality (GtkRange * range, gpointer data)
1133{
1134 set_quality ((int)gtk_range_get_value (range), data);
1135#ifdef GTK4
1136 update_menu_bar ((glwin *)data);
1137#endif
1138}
1139
1148GtkWidget * materials_tab (glwin * view, opengl_edition * ogl_edit)
1149{
1150 GtkWidget * layout = create_layout (-1, 300);
1151 GtkWidget * vbox = add_vbox_to_layout (layout, 650, -1);
1152 int i;
1153 Material * this_material = & view -> anim -> last -> img -> m_terial;
1154
1155 GtkWidget * box = adv_box (vbox, "<b>Quality</b>: ", 100, 1.0);
1156 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, create_hscale (2, 500, 1, view -> anim -> last -> img -> quality, GTK_POS_TOP, 1, 150,
1157 G_CALLBACK(scale_quality), G_CALLBACK(scroll_scale_quality), view), FALSE, FALSE, 0);
1158 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, markup_label("<b>Lightning model</b>: ", 100, -1, 0.0, 0.5), FALSE, FALSE, 10);
1159 GtkWidget * lmodel = create_combo ();
1160 GtkWidget * fix = gtk_fixed_new ();
1161 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, fix, FALSE, FALSE, 0);
1162 gtk_fixed_put (GTK_FIXED (fix), lmodel, 0, 10);
1163
1164 char * l_model[6] = {"None", "Phong", "Blinn", "Cook-Torrance-Blinn", "Cook-Torrance-Beckmann", "Cook-Torrance-GCX"};
1165 for (i=0; i<6; i++)
1166 {
1167 combo_text_append (lmodel, l_model[i]);
1168 }
1169 g_signal_connect (G_OBJECT (lmodel), "changed", G_CALLBACK(set_l_model), view);
1170 gtk_widget_set_size_request (lmodel, 100, -1);
1171 gtk_combo_box_set_active (GTK_COMBO_BOX(lmodel), this_material -> param[0]);
1172
1173 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 10);
1174 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox,
1175 check_button ("<b>Use template</b>", 100, 40, this_material -> predefine, G_CALLBACK(set_use_template_toggle), view),
1176 FALSE, FALSE, 0);
1177 box = abox (vbox, "<b>Templates</b>: ", 0);
1178 ogl_edit -> templates = create_combo ();
1179 for (i=0; i<TEMPLATES; i++)
1180 {
1182 }
1183 gtk_combo_box_set_active (GTK_COMBO_BOX(ogl_edit -> templates), this_material -> predefine-1);
1184 g_signal_connect (G_OBJECT (ogl_edit -> templates), "changed", G_CALLBACK(set_template), view);
1185 gtk_widget_set_size_request (ogl_edit -> templates, 100, -1);
1186 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, ogl_edit -> templates, FALSE, FALSE, 0);
1187 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 10);
1188 GtkWidget * hbox = create_hbox (0);
1189 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1190 ogl_edit -> param_mat = create_vbox (BSEP);
1191 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ogl_edit -> param_mat, FALSE, FALSE, 50);
1192#ifdef GTK4
1193 box = abox (ogl_edit -> param_mat, "Material properties: ", 0);
1194#else
1195 box = abox (ogl_edit -> param_mat, "Material properties: ", 5);
1196#endif
1197 GtkWidget * m_fixed;
1198 for (i=0; i<5; i++)
1199 {
1200 box = adv_box (ogl_edit -> param_mat, settings[0][i+1], 130, 0.0);
1201 ogl_edit -> m_scale[i] = create_hscale (mat_min_max[i][0], mat_min_max[i][1], 0.001, this_material -> param[i+1],
1202 GTK_POS_TOP, 3, 200, G_CALLBACK(scale_param), G_CALLBACK(scroll_scale_param), & ogl_edit -> pointer[i]);
1203 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, ogl_edit -> m_scale[i], FALSE, FALSE, 10);
1204 ogl_edit -> m_entry[i] = create_entry (G_CALLBACK(update_mat_param), 100, 15, FALSE, & ogl_edit -> pointer[i]);
1205 update_entry_double(GTK_ENTRY(ogl_edit -> m_entry[i]), this_material -> param[i+1]);
1206 m_fixed = gtk_fixed_new ();
1207 gtk_fixed_put (GTK_FIXED(m_fixed), ogl_edit -> m_entry[i], 0, 15);
1208 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, m_fixed, FALSE, FALSE, 15);
1209 }
1210 float values[] = {this_material -> albedo.x,
1211 this_material -> albedo.y,
1212 this_material -> albedo.z};
1213
1214 adv_box (ogl_edit -> param_mat, settings[0][0], 130, 0.0);
1215 add_box_child_start (GTK_ORIENTATION_VERTICAL, ogl_edit -> param_mat, create_setting_pos (0, 0, values, ogl_edit), FALSE, FALSE, 5);
1217 widget_set_sensitive (ogl_edit -> templates, this_material -> predefine);
1218 widget_set_sensitive (ogl_edit -> param_mat, ! this_material -> predefine);
1219 return layout;
1220}
1221
1222// ***************** FOG ******************* //
1223
1233void fog_param_changed (gpointer data, GLfloat u, GtkRange * range)
1234{
1235 dint * fid = (dint *)data;
1236 glwin * view = get_project_by_id (fid -> a) -> modelgl;
1237 Fog * this_fog = & view -> anim -> last -> img -> f_g;
1238 GLfloat v, w;
1239 if (fid -> b > 0)
1240 {
1241 v = this_fog -> depth[0];
1242 w = this_fog -> depth[1];
1243 if (fid -> b == 1 && u < w)
1244 {
1245 this_fog -> depth[0] = u;
1246 }
1247 else if (fid -> b == 2 && u > v)
1248 {
1249 this_fog -> depth[1] = u;
1250 }
1251 else if (view -> opengl_win)
1252 {
1253 if (fid -> b == 1)
1254 {
1255 gtk_range_set_value (range, (gdouble) (w-0.1));
1256 }
1257 else
1258 {
1259 gtk_range_set_value (range, (gdouble) (v+0.1));
1260 }
1261 }
1262 }
1263 else
1264 {
1265 this_fog -> density = u;
1266 }
1267 update (view);
1268}
1269
1280G_MODULE_EXPORT gboolean scroll_set_fog_param (GtkRange * range, GtkScrollType scroll, gdouble value, gpointer data)
1281{
1282 fog_param_changed (data, (GLfloat) value, range);
1283 return FALSE;
1284}
1285
1294G_MODULE_EXPORT void set_fog_param (GtkRange * range, gpointer data)
1295{
1296 fog_param_changed (data, (GLfloat) gtk_range_get_value (range), range);
1297}
1298
1307G_MODULE_EXPORT void set_fog_type (GtkWidget * widg, gpointer data)
1308{
1309 glwin * view = (glwin *)data;
1310 Fog * this_fog = & view -> anim -> last -> img -> f_g;
1311 this_fog -> based = gtk_combo_box_get_active (GTK_COMBO_BOX(widg));
1312 update (view);
1313}
1314
1323void setup_fog_dialogs (glwin * view, int fid)
1324{
1325 Fog * this_fog = & view -> anim -> last -> img -> f_g;
1326 this_fog -> mode = fid;
1327 if (this_fog -> mode)
1328 {
1329 show_the_widgets (view -> opengl_win -> param_fog);
1330 if (this_fog -> mode == 1)
1331 {
1332 show_the_widgets (view -> opengl_win -> depth_box);
1333 hide_the_widgets (view -> opengl_win -> dens_box);
1334 }
1335 else
1336 {
1337 hide_the_widgets (view -> opengl_win -> depth_box);
1338 show_the_widgets (view -> opengl_win -> dens_box);
1339 }
1340 }
1341 else
1342 {
1343 hide_the_widgets (view -> opengl_win -> param_fog);
1344 }
1345}
1346
1355G_MODULE_EXPORT void set_fog_mode (GtkWidget * widg, gpointer data)
1356{
1357 glwin * view = (glwin *)data;
1358 setup_fog_dialogs (view, gtk_combo_box_get_active (GTK_COMBO_BOX(widg)));
1359 update (view);
1360}
1361
1370GtkWidget * fog_tab (glwin * view, opengl_edition * ogl_edit)
1371{
1372 Fog * this_fog = & view -> anim -> last -> img -> f_g;
1373 GtkWidget * layout = create_layout (480, -1);
1374 GtkWidget * vbox = add_vbox_to_layout (layout, 480, -1);
1375
1376 GtkWidget * box = abox (vbox, "Select fog mode:", 10);
1377 GtkWidget * fogmod = create_combo ();
1378 combo_text_append (fogmod, "None");
1379 combo_text_append (fogmod, "Linear");
1380 combo_text_append (fogmod, "Exponential");
1381 combo_text_append (fogmod, "Exponential squared");
1382 gtk_widget_set_size_request (fogmod, 100, -1);
1383 gtk_combo_box_set_active (GTK_COMBO_BOX(fogmod), this_fog -> mode);
1384 g_signal_connect (G_OBJECT (fogmod), "changed", G_CALLBACK(set_fog_mode), view);
1385 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, fogmod, FALSE, FALSE, 0);
1386
1387 ogl_edit -> param_fog = create_vbox (5);
1388 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, ogl_edit -> param_fog, FALSE, FALSE, 5);
1389
1390 box = abox (ogl_edit -> param_fog, " Fog type: ", 0.0);
1391 GtkWidget * fogtype = create_combo ();
1392 combo_text_append (fogtype, "Plane based");
1393 combo_text_append (fogtype, "Range based");
1394 gtk_widget_set_size_request (fogtype, 100, -1);
1395 gtk_combo_box_set_active (GTK_COMBO_BOX(fogtype), this_fog -> based);
1396 g_signal_connect (G_OBJECT (fogtype), "changed", G_CALLBACK(set_fog_type), view);
1397 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, fogtype, FALSE, FALSE, 0);
1398
1399 ogl_edit -> dens_box = abox (ogl_edit -> param_fog, " Fog density: ", 0.0);
1400 ogl_edit -> fog_range[0] = create_hscale (0.0, 1.0, 0.0001, this_fog -> density, GTK_POS_LEFT, 5,
1401 250, G_CALLBACK(set_fog_param), G_CALLBACK(scroll_set_fog_param), & ogl_edit -> pointer[0]);
1402 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, ogl_edit -> dens_box, ogl_edit -> fog_range[0], FALSE, FALSE, 0);
1403
1404 char * depthfog[2] = {"\t depth<sup>*</sup> start: ", "\t depth<sup>*</sup> end: "};
1405
1406 ogl_edit -> depth_box = create_vbox (5);
1407 add_box_child_start (GTK_ORIENTATION_VERTICAL, ogl_edit -> param_fog, ogl_edit -> depth_box, FALSE, FALSE, 0);
1408 box = abox (ogl_edit -> depth_box, " Fog depth: ", 0.0);
1409 int i;
1410 for (i=0; i<2; i++)
1411 {
1412 box = adv_box (ogl_edit -> depth_box, depthfog[i], 170, 0.0);
1413 ogl_edit -> fog_range[i+1] = create_hscale (0.0, 100.0, 0.1, this_fog -> depth[i], GTK_POS_LEFT, 2,
1414 250, G_CALLBACK(set_fog_param), G_CALLBACK(scroll_set_fog_param), & ogl_edit -> pointer[i+1]);
1415 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, ogl_edit -> fog_range[i+1], FALSE, FALSE, 0);
1416 }
1417 add_box_child_start (GTK_ORIENTATION_VERTICAL, ogl_edit -> depth_box, markup_label("* % of the OpenGL model depth.", -1, -1, 0.5, 0.5) , FALSE, FALSE, 5);
1418
1419 float values[] = {this_fog -> color.x,
1420 this_fog -> color.y,
1421 this_fog -> color.z};
1422 add_box_child_start (GTK_ORIENTATION_VERTICAL, ogl_edit -> param_fog, create_setting_pos (4, 0, values, ogl_edit), FALSE, FALSE, 5);
1424 return layout;
1425}
1426
1434void close_advanced_opengl (gpointer data)
1435{
1436 glwin * view = (glwin *)data;
1437 view -> opengl_win -> win = destroy_this_widget (view -> opengl_win -> win);
1438 g_free (view -> opengl_win);
1439 view -> opengl_win = NULL;
1440}
1441
1442#ifdef GTK4
1451G_MODULE_EXPORT gboolean close_advanced (GtkWidget * window, gpointer data)
1452#else
1462G_MODULE_EXPORT gboolean close_advanced (GtkWidget * widg, GdkEvent * event, gpointer data)
1463#endif
1464{
1465 close_advanced_opengl (data);
1466 return FALSE;
1467}
1468
1477G_MODULE_EXPORT void opengl_advanced (GtkWidget * widg, gpointer data)
1478{
1479 glwin * view = (glwin *)data;
1480 if (view -> opengl_win == NULL)
1481 {
1482 view -> opengl_win = g_malloc0 (sizeof*view -> opengl_win);
1483 view -> opengl_win -> proj = view -> proj;
1484 int i;
1485 for (i=0; i<6; i++)
1486 {
1487 view -> opengl_win -> pointer[i].a = view -> proj;
1488 view -> opengl_win -> pointer[i].b = i;
1489 }
1490 gchar * str = g_strdup_printf ("OpenGL material aspect and light settings - %s", get_project_by_id(view -> proj) -> name);
1491 view -> opengl_win -> win = create_win (str, view -> win, FALSE, FALSE);
1492 g_free (str);
1493#ifdef DEBUG
1494 gtk_window_set_resizable (GTK_WINDOW (view -> opengl_win -> win), TRUE);
1495#endif
1496 GtkWidget * vbox = create_vbox (5);
1497 add_container_child (CONTAINER_WIN, view -> opengl_win -> win, vbox);
1498#ifdef GTK4
1499 gtk_widget_set_size_request (vbox, 650 , 650);
1500#else
1501 gtk_widget_set_size_request (vbox, 650 , 630);
1502#endif
1503 GtkWidget * notebook = gtk_notebook_new ();
1504 show_the_widgets (notebook);
1505#ifdef GTK4
1506 gtk_widget_set_vexpand (notebook, TRUE);
1507#endif
1508 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, notebook, TRUE, TRUE, 0);
1509 gtk_notebook_append_page (GTK_NOTEBOOK(notebook), materials_tab (view, view -> opengl_win), markup_label("<b>Material aspect</b>", -1, -1, 0.0, 0.5));
1510 gtk_notebook_append_page (GTK_NOTEBOOK(notebook), lights_tab (view, view -> opengl_win), markup_label("<b>Configure light sources</b>", -1, -1, 0.0, 0.5));
1511 gtk_notebook_append_page (GTK_NOTEBOOK(notebook), fog_tab (view, view -> opengl_win), markup_label("<b>Configure fog</b>", -1, -1, 0.0, 0.5));
1512 add_gtk_close_event (view -> opengl_win -> win, G_CALLBACK(close_advanced), view);
1513 }
1514 show_the_widgets (view -> opengl_win -> win);
1515 update_light_data (0, view -> opengl_win);
1516 setup_fog_dialogs (view, view -> anim -> last -> img -> f_g.mode);
1517}
gchar * param[2]
PangoLayout * layout
Definition curve.c:79
float val
Definition dlp_init.c:117
double pi
Definition global.c:195
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:633
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
Definition gtk-misc.c:714
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
project * proj
GtkWidget * add_vbox_to_layout(GtkWidget *layout, int size_x, int size_y)
Insert a vertical GtkBox in a GtkLatout then send back the GtkBox.
Definition gtk-misc.c:864
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
#define BSEP
Definition global.h:245
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2387
GtkWidget * spin_button(GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
create a spin button
Definition gtk-misc.c:1772
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1799
@ CONTAINER_WIN
Definition global.h:250
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
GtkWidget * create_layout(int x, int y)
create a GtkLayout / GtkFixed widget
Definition gtk-misc.c:880
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
GtkWidget * create_hscale(float min, float max, float delta, float val, int pos, int round, int size, GCallback handler, GCallback scroll_handler, gpointer data)
create an horizontal scale GtkWidget
Definition gtk-misc.c:744
GtkWidget * bbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1921
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:189
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
GtkWidget * abox(GtkWidget *box, char *lab, int vspace)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:1912
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
#define DEFAULT_INTENSITY
Default light intensity.
Definition glview.h:85
@ LIGHT
Definition glwin.h:100
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
position
Definition m_proj.c:47
double z
Definition ogl_draw.c:57
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
Definition glwin.h:222
Definition glwin.h:181
int fix
Definition glwin.h:183
vec3_t spot_data
Definition glwin.h:189
vec3_t direction
Definition glwin.h:186
vec3_t attenuation
Definition glwin.h:188
int show
Definition glwin.h:184
int type
Definition glwin.h:182
vec3_t position
Definition glwin.h:185
vec3_t intensity
Definition glwin.h:187
Definition global.h:97
Definition glwin.h:875
int mode
Definition glwin.h:955
Definition glwin.h:277
Definition global.h:104
float y
Definition math_3d.h:130
float x
Definition math_3d.h:130
float z
Definition math_3d.h:130
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * d_close
Definition w_advance.c:159
Light * copy_light_sources(int dima, int dimb, Light *old_sp)
create a copy of a list of light sources
Definition w_advance.c:391
G_MODULE_EXPORT void set_light_fix(GtkComboBox *box, gpointer data)
set light fix callback
Definition w_advance.c:773
void print_light_source(Light source, int i)
print light source data
Definition w_advance.c:285
G_MODULE_EXPORT void set_use_template_toggle(GtkToggleButton *but, gpointer data)
use or not OpenGL material template callback GTK3
Definition w_advance.c:969
G_MODULE_EXPORT void set_object_pos(GtkEntry *res, gpointer data)
set object position
Definition w_advance.c:713
G_MODULE_EXPORT void set_nlights_spin(GtkSpinButton *res, gpointer data)
change the number of light(s) - spin button
Definition w_advance.c:613
void set_quality(int q, glwin *view)
set OpenGL quality
Definition m_quality.c:59
gchar * settings[3][10]
Definition w_advance.c:119
G_MODULE_EXPORT void set_template(GtkComboBox *box, gpointer data)
change the OpenGL material template
Definition w_advance.c:1005
G_MODULE_EXPORT void set_fog_mode(GtkWidget *widg, gpointer data)
set fog mode callback
Definition w_advance.c:1355
int * light_source_to_be_removed(int val, image *img, opengl_edition *ogl_edit)
remove light source(s) - creating the dialog
Definition w_advance.c:245
G_MODULE_EXPORT void set_fog_type(GtkWidget *widg, gpointer data)
set OpenGL fog type
Definition w_advance.c:1307
void fog_param_changed(gpointer data, GLfloat u, GtkRange *range)
update OpenGL fog parameter
Definition w_advance.c:1233
G_MODULE_EXPORT void opengl_advanced(GtkWidget *widg, gpointer data)
create OpenGL rendering advanced window
Definition w_advance.c:1477
gchar * material_template[TEMPLATES]
Definition w_advance.c:97
G_MODULE_EXPORT gboolean scroll_scale_quality(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer data)
update OpenGL quality - scroll callback
Definition w_advance.c:1115
GtkWidget ** light_but
Definition w_advance.c:205
gchar * lpos[3]
Definition w_advance.c:137
Light init_light_source(int type, float val, float vbl)
initialize a light source
Definition w_advance.c:324
int status
Definition w_advance.c:160
GtkWidget * materials_tab(glwin *view, opengl_edition *ogl_edit)
OpenGL material parameters tab.
Definition w_advance.c:1148
Light copy_light_source(Light old_sp)
create a copy of a light source
Definition w_advance.c:368
G_MODULE_EXPORT void update_mat_param(GtkEntry *res, gpointer data)
update OpenGL material parameter - entry
Definition w_advance.c:1069
G_MODULE_EXPORT void show_this_light(GtkToggleButton *but, gpointer data)
show / hide this light callback GTK3
Definition w_advance.c:802
GtkWidget * fog_tab(glwin *view, opengl_edition *ogl_edit)
OpenGL fog parameters tab.
Definition w_advance.c:1370
G_MODULE_EXPORT gboolean scroll_set_fog_param(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer data)
update OpenGL fog parameter - scroll callback
Definition w_advance.c:1280
GtkWidget * lights_tab(glwin *view, opengl_edition *ogl_edit)
OpenGL light(s) parameters tab.
Definition w_advance.c:868
void close_advanced_opengl(gpointer data)
close OpenGL rendering window free data
Definition w_advance.c:1434
#define TEMPLATES
Definition w_advance.c:93
void show_active_light_data(opengl_edition *ogl_win, int lid, int tid)
show active light data
Definition w_advance.c:421
G_MODULE_EXPORT void show_light_param(GtkComboBox *box, gpointer data)
update light parameters based on light id in combo box
Definition w_advance.c:492
float mat_min_max[5][2]
Definition w_advance.c:113
void create_lights_combo(image *this_image, opengl_edition *ogl_win)
create light combo box
Definition w_advance.c:506
void update_light_data(int li, opengl_edition *ogl_win)
update light data
Definition w_advance.c:456
GtkWidget * create_setting_pos(int pid, int lid, float *values, opengl_edition *ogl_win)
create OpenGL setting entries table
Definition w_advance.c:827
G_MODULE_EXPORT gboolean close_advanced(GtkWidget *widg, GdkEvent *event, gpointer data)
close OpenGL rendering advanced window callback GTK3
Definition w_advance.c:1462
G_MODULE_EXPORT void scale_param(GtkRange *range, gpointer data)
update OpenGL material parameter - range callback
Definition w_advance.c:1100
void set_data_pos(vec3_t *vect, int pos, double v)
modify a vector component
Definition w_advance.c:689
int * light_list
Definition w_advance.c:204
G_MODULE_EXPORT void set_fog_param(GtkRange *range, gpointer data)
update OpenGL fog parameter - range callback
Definition w_advance.c:1294
G_MODULE_EXPORT void update_light_param(GtkEntry *res, gpointer data)
update light parameter
Definition w_advance.c:643
G_MODULE_EXPORT void toggled_delete_ligth(GtkToggleButton *but, gpointer data)
toggle delete light callback GTK3
Definition w_advance.c:183
void add_remove_lights(int val, gpointer data)
add or remove lights
Definition w_advance.c:530
G_MODULE_EXPORT void set_nlights(GtkEntry *res, gpointer data)
change the number of light(s) - entry
Definition w_advance.c:626
gchar * cpos[3]
Definition w_advance.c:138
G_MODULE_EXPORT void scale_quality(GtkRange *range, gpointer data)
update OpenGL quality - range callback
Definition w_advance.c:1132
GLfloat template_parameters[TEMPLATES][5]
Definition w_advance.c:105
G_MODULE_EXPORT void set_l_model(GtkComboBox *box, gpointer data)
change OpenGL lightning model
Definition w_advance.c:1032
void setup_fog_dialogs(glwin *view, int fid)
update OpenGL fog tab based of fog type
Definition w_advance.c:1323
void param_has_changed(gpointer data, double val)
update OpenGL material parameter
Definition w_advance.c:1047
G_MODULE_EXPORT gboolean scroll_scale_param(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer data)
update OpenGL material parameter - scroll callback
Definition w_advance.c:1086
GtkWidget * adv_box(GtkWidget *box, char *lab, int size, float xalign)
create a box with markup label
Definition w_advance.c:150
G_MODULE_EXPORT void set_light_type(GtkComboBox *box, gpointer data)
set light type callback
Definition w_advance.c:757
G_MODULE_EXPORT void run_light_source_to_be_removed(GtkDialog *win, gint response_id, gpointer data)
remove light source(s) - running the dialog
Definition w_advance.c:216
GtkWidget * templates
Definition w_axis.c:84
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73