7 #include "drawing_area.h"
8 #include "../math/3d.h"
9 #include "../graphics/constants.h"
10 #include "../graphics/individual.h"
11 #include "../graphics/family.h"
12 #include "../storage/storage.h"
14 extern GLdouble camera_pos_x;
15 extern GLdouble camera_pos_y;
16 extern GLdouble camera_pos_z;
18 GtkDrawingArea * drawing_area = NULL;
21 * The "draw" signal handler. All the OpenGL re-drawing should
22 * be done here. This is repeatedly called as the painting routine
23 * every time the 'draw' event is signalled.
25 gboolean drawing_area_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
28 unsigned int individuals_no;
29 unsigned int families_no;
30 struct familia_storage * storage;
31 struct position * pos;
33 /*** OpenGL BEGIN ***/
34 if (!gtk_widget_begin_gl (widget)) {
38 glMatrixMode (GL_MODELVIEW);
39 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
42 gluLookAt (camera_pos_x, camera_pos_y, camera_pos_z, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
44 storage = familia_storage_get_current();
45 individuals_no = storage->individuals_no;
47 for (i = 0; i < individuals_no; i++) {
48 pos = calculate_individual_position(storage->individuals[i]);
52 (pos != NULL) ? pos->x : 0,
53 (pos != NULL) ? pos->y : 0,
54 (pos != NULL) ? pos->z : -10
56 glColor3f (1.0, 1.0, 1.0);
57 graphics_render_individual();
66 families_no = storage->families_no;
68 for (i = 0; i < families_no; i++) {
70 glTranslatef(i * (GR_FAM_RADIUS + 1), -3, -10);
71 glColor3f (1.0, 1.0, 1.0);
72 graphics_render_family();
76 gtk_widget_end_gl (widget, TRUE);
83 * The "configure_event" signal handler. Any processing required when
84 * the OpenGL-capable drawing area is re-configured should be done here.
85 * Almost always it will be used to resize the OpenGL viewport when
86 * the window is resized.
88 gboolean drawing_area_configure_event (GtkWidget *widget,
89 GdkEventConfigure *event, gpointer data)
91 GtkAllocation allocation;
93 /* OpenGL widget width */
95 /* OpenGL widget height */
100 gtk_widget_get_allocation (widget, &allocation);
101 w = allocation.width;
102 h = allocation.height;
105 /*** OpenGL BEGIN ***/
106 if (!gtk_widget_begin_gl (widget))
109 glViewport (0, 0, w, h);
111 glMatrixMode (GL_PROJECTION);
113 gluPerspective (60.0, aspect, 0.1, 60.0);
114 glMatrixMode(GL_MODELVIEW);
116 gtk_widget_end_gl (widget, FALSE);
123 * The "realize" signal handler. All the OpenGL initialization
124 * should be performed here, such as default background colour,
125 * certain states etc.
127 void drawing_area_realize (GtkWidget *widget, gpointer data)
129 /*** OpenGL BEGIN ***/
130 if (!gtk_widget_begin_gl (widget)) {
134 glClearColor (0.0, 0.0, 0.0, 0.0);
135 glShadeModel (GL_FLAT);
137 gtk_widget_end_gl (widget, FALSE);
144 * The "unrealize" signal handler. Any processing required when
145 * the OpenGL-capable window is unrealized should be done here.
147 void drawing_area_unrealize (GtkWidget *widget, gpointer data)