]> Pileus Git - grits/blob - src/grits-opengl.c
Add mouse, keyboard, and motion events to GritsObject
[grits] / src / grits-opengl.c
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /**
19  * SECTION:grits-opengl
20  * @short_description: OpenGL based virtual globe
21  *
22  * #GritsOpenGL is the core rendering engine used by grits. Theoretically other
23  * renderers could be writte, but they have not been. GritsOpenGL uses the ROAM
24  * algorithm for updating surface mesh the planet. The only thing GritsOpenGL
25  * can actually render on it's own is a wireframe of a sphere.
26  *
27  * GritsOpenGL requires (at least) OpenGL 2.0.
28  */
29
30 #include <config.h>
31 #include <math.h>
32 #include <string.h>
33 #include <gdk/gdkkeysyms.h>
34 #include <gtk/gtk.h>
35 #include <GL/gl.h>
36 #include <GL/glu.h>
37
38 #include "grits-opengl.h"
39 #include "grits-util.h"
40 #include "gtkgl.h"
41 #include "roam.h"
42
43 // #define ROAM_DEBUG
44
45 /* Tessellation, "finding intersecting triangles" */
46 /* http://research.microsoft.com/pubs/70307/tr-2006-81.pdf */
47 /* http://www.opengl.org/wiki/Alpha_Blending */
48
49 /* The unsorted/sroted GLists are blank head nodes,
50  * This way us we can remove objects from the level just by fixing up links
51  * I.e. we don't need to do a lookup to remove an object if we have its GList */
52 struct RenderLevel {
53         GList unsorted;
54         GList sorted;
55 };
56
57 /***********
58  * Helpers *
59  ***********/
60 static void _set_visuals(GritsOpenGL *opengl)
61 {
62         glMatrixMode(GL_MODELVIEW);
63         glLoadIdentity();
64
65         /* Camera 1 */
66         double lat, lon, elev, rx, ry, rz;
67         grits_viewer_get_location(GRITS_VIEWER(opengl), &lat, &lon, &elev);
68         grits_viewer_get_rotation(GRITS_VIEWER(opengl), &rx, &ry, &rz);
69         glRotatef(rx, 1, 0, 0);
70         glRotatef(rz, 0, 0, 1);
71
72         /* Lighting */
73 #ifdef ROAM_DEBUG
74         float light_ambient[]  = {0.7f, 0.7f, 0.7f, 1.0f};
75         float light_diffuse[]  = {2.0f, 2.0f, 2.0f, 1.0f};
76 #else
77         float light_ambient[]  = {0.2f, 0.2f, 0.2f, 1.0f};
78         float light_diffuse[]  = {0.8f, 0.8f, 0.8f, 1.0f};
79 #endif
80         float light_position[] = {-13*EARTH_R, 1*EARTH_R, 3*EARTH_R, 1.0f};
81         glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
82         glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
83         glLightfv(GL_LIGHT0, GL_POSITION, light_position);
84         glEnable(GL_LIGHT0);
85         glEnable(GL_LIGHTING);
86
87         float material_ambient[]  = {1.0, 1.0, 1.0, 1.0};
88         float material_diffuse[]  = {1.0, 1.0, 1.0, 1.0};
89         float material_specular[] = {0.0, 0.0, 0.0, 1.0};
90         float material_emission[] = {0.0, 0.0, 0.0, 1.0};
91         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  material_ambient);
92         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  material_diffuse);
93         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular);
94         glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_emission);
95         glDisable(GL_TEXTURE_2D);
96         glDisable(GL_COLOR_MATERIAL);
97
98         /* Camera 2 */
99         glTranslatef(0, 0, -elev2rad(elev));
100         glRotatef(lat, 1, 0, 0);
101         glRotatef(-lon, 0, 1, 0);
102
103         glDisable(GL_ALPHA_TEST);
104
105         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
106         glEnable(GL_BLEND);
107
108 #ifndef ROAM_DEBUG
109         glCullFace(GL_BACK);
110         glEnable(GL_CULL_FACE);
111
112         glClearDepth(1.0);
113         glDepthFunc(GL_LEQUAL);
114         glEnable(GL_DEPTH_TEST);
115 #endif
116
117         glEnable(GL_LINE_SMOOTH);
118
119         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
120         //glShadeModel(GL_FLAT);
121
122         g_mutex_lock(opengl->sphere_lock);
123         roam_sphere_update_view(opengl->sphere);
124         g_mutex_unlock(opengl->sphere_lock);
125 }
126
127 static gboolean _foreach_object_cb(gpointer key, gpointer value, gpointer pointers)
128 {
129         struct RenderLevel *level = value;
130         GFunc    user_func = ((gpointer*)pointers)[0];
131         gpointer user_data = ((gpointer*)pointers)[1];
132         for (GList *cur = level->unsorted.next; cur; cur = cur->next)
133                 user_func(cur->data, user_data);
134         for (GList *cur = level->sorted.next;   cur; cur = cur->next)
135                 user_func(cur->data, user_data);
136         return FALSE;
137 }
138
139 static void _foreach_object(GritsOpenGL *opengl, GFunc func, gpointer user_data)
140 {
141         gpointer pointers[2] = {func, user_data};
142         g_tree_foreach(opengl->objects, _foreach_object_cb, pointers);
143 }
144
145 /*************
146  * Callbacks *
147  *************/
148 static gboolean on_configure(GritsOpenGL *opengl, GdkEventConfigure *event, gpointer _)
149 {
150         g_debug("GritsOpenGL: on_configure");
151
152         double width  = GTK_WIDGET(opengl)->allocation.width;
153         double height = GTK_WIDGET(opengl)->allocation.height;
154
155         /* Setup OpenGL Window */
156         glViewport(0, 0, width, height);
157         glMatrixMode(GL_PROJECTION);
158         glLoadIdentity();
159         double ang = atan(height/FOV_DIST);
160         gluPerspective(rad2deg(ang)*2, width/height, 10, 100*EARTH_R);
161
162 #ifndef ROAM_DEBUG
163         g_mutex_lock(opengl->sphere_lock);
164         roam_sphere_update_errors(opengl->sphere);
165         g_mutex_unlock(opengl->sphere_lock);
166 #endif
167
168         return FALSE;
169 }
170
171 static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
172 {
173         g_debug("GritsOpenGL: _draw_level - level=%-4d", (int)key);
174         GritsOpenGL *opengl = user_data;
175         struct RenderLevel *level = value;
176         int nsorted = 0, nunsorted = 0;
177         GList *cur = NULL;
178
179         /* Draw opaque objects without sorting */
180         glDepthMask(TRUE);
181         glClear(GL_DEPTH_BUFFER_BIT);
182         for (cur = level->unsorted.next; cur; cur = cur->next, nunsorted++)
183                 grits_object_draw(GRITS_OBJECT(cur->data), opengl);
184
185         /* Freeze depth buffer and draw transparent objects sorted */
186         /* TODO: sorting */
187         //glDepthMask(FALSE);
188         glAlphaFunc(GL_GREATER, 0.1);
189         for (cur = level->sorted.next; cur; cur = cur->next, nsorted++)
190                 grits_object_draw(GRITS_OBJECT(cur->data), opengl);
191
192         /* TODO: Prune empty levels */
193
194         g_debug("GritsOpenGL: _draw_level - drew %d,%d objects",
195                         nunsorted, nsorted);
196         return FALSE;
197 }
198
199 static gboolean on_expose(GritsOpenGL *opengl, GdkEventExpose *event, gpointer _)
200 {
201         g_debug("GritsOpenGL: on_expose - begin");
202
203         glClear(GL_COLOR_BUFFER_BIT);
204
205         _set_visuals(opengl);
206 #ifdef ROAM_DEBUG
207         glColor4f(1.0, 1.0, 1.0, 1.0);
208         glLineWidth(2);
209         glDisable(GL_TEXTURE_2D);
210         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
211         roam_sphere_draw(opengl->sphere);
212         (void)_draw_level;
213         //roam_sphere_draw_normals(opengl->sphere);
214 #else
215         g_mutex_lock(opengl->objects_lock);
216         g_tree_foreach(opengl->objects, _draw_level, opengl);
217         if (opengl->wireframe) {
218                 glClear(GL_DEPTH_BUFFER_BIT);
219                 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
220                 roam_sphere_draw(opengl->sphere);
221                 g_tree_foreach(opengl->objects, _draw_level, opengl);
222         }
223         g_mutex_unlock(opengl->objects_lock);
224 #endif
225
226         gtk_gl_end(GTK_WIDGET(opengl));
227
228         g_debug("GritsOpenGL: on_expose - end\n");
229         return FALSE;
230 }
231
232 static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpointer _)
233 {
234         gdouble height = GTK_WIDGET(opengl)->allocation.height;
235         gdouble gl_x   = event->x;
236         gdouble gl_y   = height - event->y;
237
238         /* Configure view */
239         gint viewport[4];
240         gdouble projection[16];
241         glGetIntegerv(GL_VIEWPORT, viewport);
242         glGetDoublev(GL_PROJECTION_MATRIX, projection);
243
244         glMatrixMode(GL_PROJECTION);
245         glPushMatrix();
246         glLoadIdentity();
247         gluPickMatrix(gl_x, gl_y, 2, 2, viewport);
248         glMultMatrixd(projection);
249
250         /* Prepare for picking */
251         guint buffer[100][4] = {};
252         glSelectBuffer(G_N_ELEMENTS(buffer), (guint*)buffer);
253         glRenderMode(GL_SELECT);
254         glInitNames();
255
256         /* Run picking */
257         g_mutex_lock(opengl->objects_lock);
258         _foreach_object(opengl, (GFunc)grits_object_pick_begin, opengl);
259         int hits = glRenderMode(GL_RENDER);
260         g_debug("GritsOpenGL: on_motion_notify - hits=%d ev=%.0lf,%.0lf",
261                         hits, gl_x, gl_y);
262         for (int i = 0; i < hits; i++) {
263                 //g_debug("\tHit: %d",     i);
264                 //g_debug("\t\tcount: %d", buffer[i][0]);
265                 //g_debug("\t\tz1:    %f", (float)buffer[i][1]/0x7fffffff);
266                 //g_debug("\t\tz2:    %f", (float)buffer[i][2]/0x7fffffff);
267                 //g_debug("\t\tname:  %p", (gpointer)buffer[i][3]);
268                 GritsObject *object = GRITS_OBJECT(buffer[i][3]);
269                 grits_object_pick_pointer(object, gl_x, gl_y);
270         }
271         _foreach_object(opengl, (GFunc)grits_object_pick_end, NULL);
272         g_mutex_unlock(opengl->objects_lock);
273
274         /* Cleanup */
275         glMatrixMode(GL_PROJECTION);
276         glPopMatrix();
277
278         return FALSE;
279 }
280
281 static gboolean on_key_press(GritsOpenGL *opengl, GdkEventKey *event, gpointer _)
282 {
283         g_debug("GritsOpenGL: on_key_press - key=%x, state=%x, plus=%x",
284                         event->keyval, event->state, GDK_plus);
285
286         guint kv = event->keyval;
287         /* Testing */
288         if (kv == GDK_w) {
289                 opengl->wireframe = !opengl->wireframe;
290                 gtk_widget_queue_draw(GTK_WIDGET(opengl));
291         }
292 #ifdef ROAM_DEBUG
293         else if (kv == GDK_n) roam_sphere_split_one(opengl->sphere);
294         else if (kv == GDK_p) roam_sphere_merge_one(opengl->sphere);
295         else if (kv == GDK_r) roam_sphere_split_merge(opengl->sphere);
296         else if (kv == GDK_u) roam_sphere_update_errors(opengl->sphere);
297         gtk_widget_queue_draw(GTK_WIDGET(opengl));
298 #endif
299         return FALSE;
300 }
301
302 static gboolean on_chained_event(GritsOpenGL *opengl, GdkEvent *event, gpointer _)
303 {
304         _foreach_object(opengl, (GFunc)grits_object_event, event);
305         return FALSE;
306 }
307
308 static gboolean _update_errors_cb(gpointer _opengl)
309 {
310         GritsOpenGL *opengl = _opengl;
311         g_mutex_lock(opengl->sphere_lock);
312         roam_sphere_update_errors(opengl->sphere);
313         g_mutex_unlock(opengl->sphere_lock);
314         opengl->ue_source = 0;
315         return FALSE;
316 }
317 static void on_view_changed(GritsOpenGL *opengl,
318                 gdouble _1, gdouble _2, gdouble _3)
319 {
320         g_debug("GritsOpenGL: on_view_changed");
321         _set_visuals(opengl);
322 #ifndef ROAM_DEBUG
323         if (!opengl->ue_source)
324                 opengl->ue_source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+30,
325                                 _update_errors_cb, opengl, NULL);
326         //roam_sphere_update_errors(opengl->sphere);
327 #else
328         (void)_update_errors_cb;
329 #endif
330 }
331
332 static gboolean on_idle(GritsOpenGL *opengl)
333 {
334         //g_debug("GritsOpenGL: on_idle");
335         g_mutex_lock(opengl->sphere_lock);
336         if (roam_sphere_split_merge(opengl->sphere))
337                 gtk_widget_queue_draw(GTK_WIDGET(opengl));
338         g_mutex_unlock(opengl->sphere_lock);
339         return TRUE;
340 }
341
342 static void on_realize(GritsOpenGL *opengl, gpointer _)
343 {
344         g_debug("GritsOpenGL: on_realize");
345         gtk_gl_begin(GTK_WIDGET(opengl));
346
347         /* Connect signals and idle functions now that opengl is fully initialized */
348         gtk_widget_add_events(GTK_WIDGET(opengl), GDK_KEY_PRESS_MASK);
349         g_signal_connect(opengl, "configure-event",  G_CALLBACK(on_configure),    NULL);
350         g_signal_connect(opengl, "expose-event",     G_CALLBACK(on_expose),       NULL);
351
352         g_signal_connect(opengl, "key-press-event",  G_CALLBACK(on_key_press),    NULL);
353
354         g_signal_connect(opengl, "location-changed", G_CALLBACK(on_view_changed), NULL);
355         g_signal_connect(opengl, "rotation-changed", G_CALLBACK(on_view_changed), NULL);
356
357         g_signal_connect(opengl, "motion-notify-event", G_CALLBACK(on_motion_notify), NULL);
358         g_signal_connect_after(opengl, "key-press-event",      G_CALLBACK(on_chained_event), NULL);
359         g_signal_connect_after(opengl, "key-release-event",    G_CALLBACK(on_chained_event), NULL);
360         g_signal_connect_after(opengl, "button-press-event",   G_CALLBACK(on_chained_event), NULL);
361         g_signal_connect_after(opengl, "button-release-event", G_CALLBACK(on_chained_event), NULL);
362         g_signal_connect_after(opengl, "motion-notify-event",  G_CALLBACK(on_chained_event), NULL);
363
364 #ifndef ROAM_DEBUG
365         opengl->sm_source[0] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+30, 33,  (GSourceFunc)on_idle, opengl, NULL);
366         opengl->sm_source[1] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+10, 500, (GSourceFunc)on_idle, opengl, NULL);
367 #else
368         (void)on_idle;
369         (void)_update_errors_cb;
370 #endif
371
372         /* Re-queue resize incase configure was triggered before realize */
373         gtk_widget_queue_resize(GTK_WIDGET(opengl));
374 }
375
376 /*********************
377  * GritsViewer methods *
378  *********************/
379 /**
380  * grits_opengl_new:
381  * @plugins: the plugins store to use
382  * @prefs:   the preferences object to use
383  *
384  * Create a new OpenGL renderer.
385  *
386  * Returns: the new #GritsOpenGL
387  */
388 GritsViewer *grits_opengl_new(GritsPlugins *plugins, GritsPrefs *prefs)
389 {
390         g_debug("GritsOpenGL: new");
391         GritsViewer *opengl = g_object_new(GRITS_TYPE_OPENGL, NULL);
392         grits_viewer_setup(opengl, plugins, prefs);
393         return opengl;
394 }
395
396 static void grits_opengl_center_position(GritsViewer *_opengl, gdouble lat, gdouble lon, gdouble elev)
397 {
398         glRotatef(lon, 0, 1, 0);
399         glRotatef(-lat, 1, 0, 0);
400         glTranslatef(0, 0, elev2rad(elev));
401 }
402
403 static void grits_opengl_project(GritsViewer *_opengl,
404                 gdouble lat, gdouble lon, gdouble elev,
405                 gdouble *px, gdouble *py, gdouble *pz)
406 {
407         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
408         gdouble x, y, z;
409         lle2xyz(lat, lon, elev, &x, &y, &z);
410         gluProject(x, y, z,
411                 opengl->sphere->view->model,
412                 opengl->sphere->view->proj,
413                 opengl->sphere->view->view,
414                 px, py, pz);
415 }
416
417 static void grits_opengl_set_height_func(GritsViewer *_opengl, GritsBounds *bounds,
418                 RoamHeightFunc height_func, gpointer user_data, gboolean update)
419 {
420         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
421         /* TODO: get points? */
422         g_mutex_lock(opengl->sphere_lock);
423         GList *triangles = roam_sphere_get_intersect(opengl->sphere, TRUE,
424                         bounds->n, bounds->s, bounds->e, bounds->w);
425         for (GList *cur = triangles; cur; cur = cur->next) {
426                 RoamTriangle *tri = cur->data;
427                 RoamPoint *points[] = {tri->p.l, tri->p.m, tri->p.r, tri->split};
428                 for (int i = 0; i < G_N_ELEMENTS(points); i++) {
429                         if (bounds->n >= points[i]->lat && points[i]->lat >= bounds->s &&
430                             bounds->e >= points[i]->lon && points[i]->lon >= bounds->w) {
431                                 points[i]->height_func = height_func;
432                                 points[i]->height_data = user_data;
433                                 roam_point_update_height(points[i]);
434                         }
435                 }
436         }
437         g_list_free(triangles);
438         g_mutex_unlock(opengl->sphere_lock);
439 }
440
441 static void _grits_opengl_clear_height_func_rec(RoamTriangle *root)
442 {
443         if (!root)
444                 return;
445         RoamPoint *points[] = {root->p.l, root->p.m, root->p.r, root->split};
446         for (int i = 0; i < G_N_ELEMENTS(points); i++) {
447                 points[i]->height_func = NULL;
448                 points[i]->height_data = NULL;
449                 roam_point_update_height(points[i]);
450         }
451         _grits_opengl_clear_height_func_rec(root->kids[0]);
452         _grits_opengl_clear_height_func_rec(root->kids[1]);
453 }
454
455 static void grits_opengl_clear_height_func(GritsViewer *_opengl)
456 {
457         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
458         for (int i = 0; i < G_N_ELEMENTS(opengl->sphere->roots); i++)
459                 _grits_opengl_clear_height_func_rec(opengl->sphere->roots[i]);
460 }
461
462 static gpointer grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
463                 gint key, gboolean sort)
464 {
465         g_assert(GRITS_IS_OPENGL(_opengl));
466         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
467         g_mutex_lock(opengl->objects_lock);
468         struct RenderLevel *level = g_tree_lookup(opengl->objects, (gpointer)key);
469         if (!level) {
470                 level = g_new0(struct RenderLevel, 1);
471                 g_tree_insert(opengl->objects, (gpointer)key, level);
472         }
473         GList *list = sort ? &level->sorted : &level->unsorted;
474         /* Put the link in the list */
475         GList *link = g_new0(GList, 1);
476         link->data = object;
477         link->prev = list;
478         link->next = list->next;
479         if (list->next)
480                 list->next->prev = link;
481         list->next = link;
482         g_mutex_unlock(opengl->objects_lock);
483         return link;
484 }
485
486 static GritsObject *grits_opengl_remove(GritsViewer *_opengl, gpointer _link)
487 {
488         g_assert(GRITS_IS_OPENGL(_opengl));
489         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
490         GList *link = _link;
491         g_mutex_lock(opengl->objects_lock);
492         GritsObject *object = link->data;
493         /* Just unlink and free it, link->prev is assured */
494         link->prev->next = link->next;
495         if (link->next)
496                 link->next->prev = link->prev;
497         g_mutex_unlock(opengl->objects_lock);
498         g_free(link);
499         g_object_unref(object);
500         return object;
501 }
502
503 /****************
504  * GObject code *
505  ****************/
506 static int _objects_cmp(gconstpointer _a, gconstpointer _b, gpointer _)
507 {
508         gint a = (int)_a, b = (int)_b;
509         return a < b ? -1 :
510                a > b ?  1 : 0;
511 }
512 static void _objects_free(gpointer value)
513 {
514         struct RenderLevel *level = value;
515         if (level->sorted.next)
516                 g_list_free(level->sorted.next);
517         if (level->unsorted.next)
518                 g_list_free(level->unsorted.next);
519         g_free(level);
520 }
521
522 G_DEFINE_TYPE(GritsOpenGL, grits_opengl, GRITS_TYPE_VIEWER);
523 static void grits_opengl_init(GritsOpenGL *opengl)
524 {
525         g_debug("GritsOpenGL: init");
526         opengl->objects      = g_tree_new_full(_objects_cmp, NULL, NULL, _objects_free);
527         opengl->objects_lock = g_mutex_new();
528         opengl->sphere       = roam_sphere_new(opengl);
529         opengl->sphere_lock  = g_mutex_new();
530         gtk_gl_enable(GTK_WIDGET(opengl));
531         g_signal_connect(opengl, "realize", G_CALLBACK(on_realize), NULL);
532 }
533 static void grits_opengl_dispose(GObject *_opengl)
534 {
535         g_debug("GritsOpenGL: dispose");
536         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
537         if (opengl->sm_source[0]) {
538                 g_source_remove(opengl->sm_source[0]);
539                 opengl->sm_source[0] = 0;
540         }
541         if (opengl->sm_source[1]) {
542                 g_source_remove(opengl->sm_source[1]);
543                 opengl->sm_source[1] = 0;
544         }
545         if (opengl->ue_source) {
546                 g_source_remove(opengl->ue_source);
547                 opengl->ue_source = 0;
548         }
549         G_OBJECT_CLASS(grits_opengl_parent_class)->dispose(_opengl);
550 }
551 static void grits_opengl_finalize(GObject *_opengl)
552 {
553         g_debug("GritsOpenGL: finalize");
554         GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
555         roam_sphere_free(opengl->sphere);
556         g_tree_destroy(opengl->objects);
557         g_mutex_free(opengl->objects_lock);
558         g_mutex_free(opengl->sphere_lock);
559         G_OBJECT_CLASS(grits_opengl_parent_class)->finalize(_opengl);
560 }
561 static void grits_opengl_class_init(GritsOpenGLClass *klass)
562 {
563         g_debug("GritsOpenGL: class_init");
564         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
565         gobject_class->finalize = grits_opengl_finalize;
566         gobject_class->dispose = grits_opengl_dispose;
567
568         GritsViewerClass *viewer_class = GRITS_VIEWER_CLASS(klass);
569         viewer_class->center_position   = grits_opengl_center_position;
570         viewer_class->project           = grits_opengl_project;
571         viewer_class->clear_height_func = grits_opengl_clear_height_func;
572         viewer_class->set_height_func   = grits_opengl_set_height_func;
573         viewer_class->add               = grits_opengl_add;
574         viewer_class->remove            = grits_opengl_remove;
575 }