]> Pileus Git - grits/blobdiff - src/grits-opengl.c
Add mouse enter/leave signals to objects
[grits] / src / grits-opengl.c
index d65ea3f46fa5f30f9b00b17e26086444516baf86..423c849dba2fa53f568c0672db4c6213add4a86a 100644 (file)
  */
 
 /**
- * SECTION:gis-opengl
+ * SECTION:grits-opengl
  * @short_description: OpenGL based virtual globe
  *
- * #GisOpenGL is the core rendering engine used by libgis. Theoretically other
- * renderers could be writte, but they have not been. GisOpenGL uses the ROAM
- * algorithm for updating surface mesh the planet. The only thing GisOpenGL can
- * actually render on it's own is a wireframe of a sphere.
+ * #GritsOpenGL is the core rendering engine used by grits. Theoretically other
+ * renderers could be writte, but they have not been. GritsOpenGL uses the ROAM
+ * algorithm for updating surface mesh the planet. The only thing GritsOpenGL
+ * can actually render on it's own is a wireframe of a sphere.
  *
- * GisOpenGL relies on #GtkGlExt and requires (at least) OpenGL 2.0.
+ * GritsOpenGL requires (at least) OpenGL 2.0.
  */
 
 #include <config.h>
 #include <string.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
-#include <gtk/gtkgl.h>
 #include <GL/gl.h>
 #include <GL/glu.h>
 
-#include "gis-opengl.h"
-#include "gis-util.h"
+#include "grits-opengl.h"
+#include "grits-util.h"
+#include "gtkgl.h"
 #include "roam.h"
 
 // #define ROAM_DEBUG
 /* http://research.microsoft.com/pubs/70307/tr-2006-81.pdf */
 /* http://www.opengl.org/wiki/Alpha_Blending */
 
+/* The unsorted/sroted GLists are blank head nodes,
+ * This way us we can remove objects from the level just by fixing up links
+ * I.e. we don't need to do a lookup to remove an object if we have its GList */
+struct RenderLevel {
+       GList unsorted;
+       GList sorted;
+};
+
 /***********
  * Helpers *
  ***********/
-static void _set_visuals(GisOpenGL *opengl)
+static void _set_visuals(GritsOpenGL *opengl)
 {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
 
        /* Camera 1 */
        double lat, lon, elev, rx, ry, rz;
-       gis_viewer_get_location(GIS_VIEWER(opengl), &lat, &lon, &elev);
-       gis_viewer_get_rotation(GIS_VIEWER(opengl), &rx, &ry, &rz);
+       grits_viewer_get_location(GRITS_VIEWER(opengl), &lat, &lon, &elev);
+       grits_viewer_get_rotation(GRITS_VIEWER(opengl), &rx, &ry, &rz);
        glRotatef(rx, 1, 0, 0);
        glRotatef(rz, 0, 0, 1);
 
@@ -67,7 +75,7 @@ static void _set_visuals(GisOpenGL *opengl)
        float light_diffuse[]  = {2.0f, 2.0f, 2.0f, 1.0f};
 #else
        float light_ambient[]  = {0.2f, 0.2f, 0.2f, 1.0f};
-       float light_diffuse[]  = {5.0f, 5.0f, 5.0f, 1.0f};
+       float light_diffuse[]  = {0.8f, 0.8f, 0.8f, 1.0f};
 #endif
        float light_position[] = {-13*EARTH_R, 1*EARTH_R, 3*EARTH_R, 1.0f};
        glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
@@ -76,9 +84,9 @@ static void _set_visuals(GisOpenGL *opengl)
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
 
-       float material_ambient[]  = {0.2, 0.2, 0.2, 1.0};
-       float material_diffuse[]  = {0.8, 0.8, 0.8, 1.0};
-       float material_specular[] = {0.1, 0.1, 0.1, 1.0};
+       float material_ambient[]  = {1.0, 1.0, 1.0, 1.0};
+       float material_diffuse[]  = {1.0, 1.0, 1.0, 1.0};
+       float material_specular[] = {0.0, 0.0, 0.0, 1.0};
        float material_emission[] = {0.0, 0.0, 0.0, 1.0};
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  material_ambient);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  material_diffuse);
@@ -116,21 +124,30 @@ static void _set_visuals(GisOpenGL *opengl)
        g_mutex_unlock(opengl->sphere_lock);
 }
 
+static gboolean _foreach_object_cb(gpointer key, gpointer value, gpointer pointers)
+{
+       struct RenderLevel *level = value;
+       GFunc    user_func = ((gpointer*)pointers)[0];
+       gpointer user_data = ((gpointer*)pointers)[1];
+       for (GList *cur = level->unsorted.next; cur; cur = cur->next)
+               user_func(cur->data, user_data);
+       for (GList *cur = level->sorted.next;   cur; cur = cur->next)
+               user_func(cur->data, user_data);
+       return FALSE;
+}
+
+static void _foreach_object(GritsOpenGL *opengl, GFunc func, gpointer user_data)
+{
+       gpointer pointers[2] = {func, user_data};
+       g_tree_foreach(opengl->objects, _foreach_object_cb, pointers);
+}
 
 /*************
  * Callbacks *
  *************/
-/* The unsorted/sroted GLists are blank head nodes,
- * This way us we can remove objects from the level just by fixing up links
- * I.e. we don't need to do a lookup to remove an object if we have its GList */
-struct RenderLevel {
-       GList unsorted;
-       GList sorted;
-};
-
-static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpointer _)
+static gboolean on_configure(GritsOpenGL *opengl, GdkEventConfigure *event, gpointer _)
 {
-       g_debug("GisOpenGL: on_configure");
+       g_debug("GritsOpenGL: on_configure");
 
        double width  = GTK_WIDGET(opengl)->allocation.width;
        double height = GTK_WIDGET(opengl)->allocation.height;
@@ -140,7 +157,7 @@ static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpoint
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        double ang = atan(height/FOV_DIST);
-       gluPerspective(rad2deg(ang)*2, width/height, 1000, 10*EARTH_R);
+       gluPerspective(rad2deg(ang)*2, width/height, 10, 100*EARTH_R);
 
 #ifndef ROAM_DEBUG
        g_mutex_lock(opengl->sphere_lock);
@@ -153,8 +170,8 @@ static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpoint
 
 static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
 {
-       g_debug("GisOpenGL: _draw_level - level=%-4d", (int)key);
-       GisOpenGL *opengl = user_data;
+       g_debug("GritsOpenGL: _draw_level - level=%-4d", (int)key);
+       GritsOpenGL *opengl = user_data;
        struct RenderLevel *level = value;
        int nsorted = 0, nunsorted = 0;
        GList *cur = NULL;
@@ -163,25 +180,25 @@ static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
        glDepthMask(TRUE);
        glClear(GL_DEPTH_BUFFER_BIT);
        for (cur = level->unsorted.next; cur; cur = cur->next, nunsorted++)
-               gis_object_draw( GIS_OBJECT(cur->data), opengl);
+               grits_object_draw(GRITS_OBJECT(cur->data), opengl);
 
        /* Freeze depth buffer and draw transparent objects sorted */
        /* TODO: sorting */
        //glDepthMask(FALSE);
        glAlphaFunc(GL_GREATER, 0.1);
        for (cur = level->sorted.next; cur; cur = cur->next, nsorted++)
-               gis_object_draw(GIS_OBJECT(cur->data), opengl);
+               grits_object_draw(GRITS_OBJECT(cur->data), opengl);
 
        /* TODO: Prune empty levels */
 
-       g_debug("GisOpenGL: _draw_level - drew %d,%d objects",
+       g_debug("GritsOpenGL: _draw_level - drew %d,%d objects",
                        nunsorted, nsorted);
        return FALSE;
 }
 
-static gboolean on_expose(GisOpenGL *opengl, GdkEventExpose *event, gpointer _)
+static gboolean on_expose(GritsOpenGL *opengl, GdkEventExpose *event, gpointer _)
 {
-       g_debug("GisOpenGL: on_expose - begin");
+       g_debug("GritsOpenGL: on_expose - begin");
 
        glClear(GL_COLOR_BUFFER_BIT);
 
@@ -201,20 +218,69 @@ static gboolean on_expose(GisOpenGL *opengl, GdkEventExpose *event, gpointer _)
                glClear(GL_DEPTH_BUFFER_BIT);
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
                roam_sphere_draw(opengl->sphere);
+               g_tree_foreach(opengl->objects, _draw_level, opengl);
        }
        g_mutex_unlock(opengl->objects_lock);
 #endif
 
-       GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl));
-       gdk_gl_drawable_swap_buffers(gldrawable);
+       gtk_gl_end(GTK_WIDGET(opengl));
 
-       g_debug("GisOpenGL: on_expose - end\n");
+       g_debug("GritsOpenGL: on_expose - end\n");
        return FALSE;
 }
 
-static gboolean on_key_press(GisOpenGL *opengl, GdkEventKey *event, gpointer _)
+static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpointer _)
 {
-       g_debug("GisOpenGL: on_key_press - key=%x, state=%x, plus=%x",
+       gdouble height = GTK_WIDGET(opengl)->allocation.height;
+       gdouble gl_x   = event->x;
+       gdouble gl_y   = height - event->y;
+
+       /* Configure view */
+       gint viewport[4];
+       gdouble projection[16];
+       glGetIntegerv(GL_VIEWPORT, viewport);
+       glGetDoublev(GL_PROJECTION_MATRIX, projection);
+
+       glMatrixMode(GL_PROJECTION);
+       glPushMatrix();
+       glLoadIdentity();
+       gluPickMatrix(gl_x, gl_y, 2, 2, viewport);
+       glMultMatrixd(projection);
+
+       /* Prepare for picking */
+       guint buffer[100][4] = {};
+       glSelectBuffer(G_N_ELEMENTS(buffer), (guint*)buffer);
+       glRenderMode(GL_SELECT);
+       glInitNames();
+
+       /* Run picking */
+       g_mutex_lock(opengl->objects_lock);
+       _foreach_object(opengl, (GFunc)grits_object_pick_begin, opengl);
+       int hits = glRenderMode(GL_RENDER);
+       g_debug("GritsOpenGL: on_motion_notify - hits=%d ev=%.0lf,%.0lf",
+                       hits, gl_x, gl_y);
+       for (int i = 0; i < hits; i++) {
+               //g_debug("\tHit: %d",     i);
+               //g_debug("\t\tcount: %d", buffer[i][0]);
+               //g_debug("\t\tz1:    %f", (float)buffer[i][1]/0x7fffffff);
+               //g_debug("\t\tz2:    %f", (float)buffer[i][2]/0x7fffffff);
+               //g_debug("\t\tname:  %p", (gpointer)buffer[i][3]);
+               GritsObject *object = GRITS_OBJECT(buffer[i][3]);
+               grits_object_pick_pointer(object, gl_x, gl_y);
+       }
+       _foreach_object(opengl, (GFunc)grits_object_pick_end, NULL);
+       g_mutex_unlock(opengl->objects_lock);
+
+       /* Cleanup */
+       glMatrixMode(GL_PROJECTION);
+       glPopMatrix();
+
+       return FALSE;
+}
+
+static gboolean on_key_press(GritsOpenGL *opengl, GdkEventKey *event, gpointer _)
+{
+       g_debug("GritsOpenGL: on_key_press - key=%x, state=%x, plus=%x",
                        event->keyval, event->state, GDK_plus);
 
        guint kv = event->keyval;
@@ -235,17 +301,17 @@ static gboolean on_key_press(GisOpenGL *opengl, GdkEventKey *event, gpointer _)
 
 static gboolean _update_errors_cb(gpointer _opengl)
 {
-       GisOpenGL *opengl = _opengl;
+       GritsOpenGL *opengl = _opengl;
        g_mutex_lock(opengl->sphere_lock);
        roam_sphere_update_errors(opengl->sphere);
        g_mutex_unlock(opengl->sphere_lock);
        opengl->ue_source = 0;
        return FALSE;
 }
-static void on_view_changed(GisOpenGL *opengl,
+static void on_view_changed(GritsOpenGL *opengl,
                gdouble _1, gdouble _2, gdouble _3)
 {
-       g_debug("GisOpenGL: on_view_changed");
+       g_debug("GritsOpenGL: on_view_changed");
        _set_visuals(opengl);
 #ifndef ROAM_DEBUG
        if (!opengl->ue_source)
@@ -257,9 +323,9 @@ static void on_view_changed(GisOpenGL *opengl,
 #endif
 }
 
-static gboolean on_idle(GisOpenGL *opengl)
+static gboolean on_idle(GritsOpenGL *opengl)
 {
-       //g_debug("GisOpenGL: on_idle");
+       //g_debug("GritsOpenGL: on_idle");
        g_mutex_lock(opengl->sphere_lock);
        if (roam_sphere_split_merge(opengl->sphere))
                gtk_widget_queue_draw(GTK_WIDGET(opengl));
@@ -267,15 +333,10 @@ static gboolean on_idle(GisOpenGL *opengl)
        return TRUE;
 }
 
-static void on_realize(GisOpenGL *opengl, gpointer _)
+static void on_realize(GritsOpenGL *opengl, gpointer _)
 {
-       g_debug("GisOpenGL: on_realize");
-
-       /* Start OpenGL */
-       GdkGLContext   *glcontext  = gtk_widget_get_gl_context(GTK_WIDGET(opengl));
-       GdkGLDrawable  *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl));
-       if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
-               g_assert_not_reached();
+       g_debug("GritsOpenGL: on_realize");
+       gtk_gl_begin(GTK_WIDGET(opengl));
 
        /* Connect signals and idle functions now that opengl is fully initialized */
        gtk_widget_add_events(GTK_WIDGET(opengl), GDK_KEY_PRESS_MASK);
@@ -287,6 +348,7 @@ static void on_realize(GisOpenGL *opengl, gpointer _)
        g_signal_connect(opengl, "location-changed", G_CALLBACK(on_view_changed), NULL);
        g_signal_connect(opengl, "rotation-changed", G_CALLBACK(on_view_changed), NULL);
 
+       g_signal_connect(opengl, "motion-notify-event", G_CALLBACK(on_motion_notify), NULL);
 #ifndef ROAM_DEBUG
        opengl->sm_source[0] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+30, 33,  (GSourceFunc)on_idle, opengl, NULL);
        opengl->sm_source[1] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+10, 500, (GSourceFunc)on_idle, opengl, NULL);
@@ -300,37 +362,37 @@ static void on_realize(GisOpenGL *opengl, gpointer _)
 }
 
 /*********************
- * GisViewer methods *
+ * GritsViewer methods *
  *********************/
 /**
- * gis_opengl_new:
+ * grits_opengl_new:
  * @plugins: the plugins store to use
  * @prefs:   the preferences object to use
  *
  * Create a new OpenGL renderer.
  *
- * Returns: the new #GisOpenGL
+ * Returns: the new #GritsOpenGL
  */
-GisViewer *gis_opengl_new(GisPlugins *plugins, GisPrefs *prefs)
+GritsViewer *grits_opengl_new(GritsPlugins *plugins, GritsPrefs *prefs)
 {
-       g_debug("GisOpenGL: new");
-       GisViewer *opengl = g_object_new(GIS_TYPE_OPENGL, NULL);
-       gis_viewer_setup(opengl, plugins, prefs);
+       g_debug("GritsOpenGL: new");
+       GritsViewer *opengl = g_object_new(GRITS_TYPE_OPENGL, NULL);
+       grits_viewer_setup(opengl, plugins, prefs);
        return opengl;
 }
 
-static void gis_opengl_center_position(GisViewer *_opengl, gdouble lat, gdouble lon, gdouble elev)
+static void grits_opengl_center_position(GritsViewer *_opengl, gdouble lat, gdouble lon, gdouble elev)
 {
        glRotatef(lon, 0, 1, 0);
        glRotatef(-lat, 1, 0, 0);
        glTranslatef(0, 0, elev2rad(elev));
 }
 
-static void gis_opengl_project(GisViewer *_opengl,
+static void grits_opengl_project(GritsViewer *_opengl,
                gdouble lat, gdouble lon, gdouble elev,
                gdouble *px, gdouble *py, gdouble *pz)
 {
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        gdouble x, y, z;
        lle2xyz(lat, lon, elev, &x, &y, &z);
        gluProject(x, y, z,
@@ -340,10 +402,10 @@ static void gis_opengl_project(GisViewer *_opengl,
                px, py, pz);
 }
 
-static void gis_opengl_set_height_func(GisViewer *_opengl, GisBounds *bounds,
+static void grits_opengl_set_height_func(GritsViewer *_opengl, GritsBounds *bounds,
                RoamHeightFunc height_func, gpointer user_data, gboolean update)
 {
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        /* TODO: get points? */
        g_mutex_lock(opengl->sphere_lock);
        GList *triangles = roam_sphere_get_intersect(opengl->sphere, TRUE,
@@ -364,7 +426,7 @@ static void gis_opengl_set_height_func(GisViewer *_opengl, GisBounds *bounds,
        g_mutex_unlock(opengl->sphere_lock);
 }
 
-static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
+static void _grits_opengl_clear_height_func_rec(RoamTriangle *root)
 {
        if (!root)
                return;
@@ -374,22 +436,22 @@ static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
                points[i]->height_data = NULL;
                roam_point_update_height(points[i]);
        }
-       _gis_opengl_clear_height_func_rec(root->kids[0]);
-       _gis_opengl_clear_height_func_rec(root->kids[1]);
+       _grits_opengl_clear_height_func_rec(root->kids[0]);
+       _grits_opengl_clear_height_func_rec(root->kids[1]);
 }
 
-static void gis_opengl_clear_height_func(GisViewer *_opengl)
+static void grits_opengl_clear_height_func(GritsViewer *_opengl)
 {
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        for (int i = 0; i < G_N_ELEMENTS(opengl->sphere->roots); i++)
-               _gis_opengl_clear_height_func_rec(opengl->sphere->roots[i]);
+               _grits_opengl_clear_height_func_rec(opengl->sphere->roots[i]);
 }
 
-static gpointer gis_opengl_add(GisViewer *_opengl, GisObject *object,
+static gpointer grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
                gint key, gboolean sort)
 {
-       g_assert(GIS_IS_OPENGL(_opengl));
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_assert(GRITS_IS_OPENGL(_opengl));
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        g_mutex_lock(opengl->objects_lock);
        struct RenderLevel *level = g_tree_lookup(opengl->objects, (gpointer)key);
        if (!level) {
@@ -409,20 +471,20 @@ static gpointer gis_opengl_add(GisViewer *_opengl, GisObject *object,
        return link;
 }
 
-static GisObject *gis_opengl_remove(GisViewer *_opengl, gpointer _link)
+static GritsObject *grits_opengl_remove(GritsViewer *_opengl, gpointer _link)
 {
-       g_assert(GIS_IS_OPENGL(_opengl));
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
-       g_mutex_lock(opengl->objects_lock);
+       g_assert(GRITS_IS_OPENGL(_opengl));
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        GList *link = _link;
-       GisObject *object = link->data;
+       g_mutex_lock(opengl->objects_lock);
+       GritsObject *object = link->data;
        /* Just unlink and free it, link->prev is assured */
        link->prev->next = link->next;
        if (link->next)
                link->next->prev = link->prev;
+       g_mutex_unlock(opengl->objects_lock);
        g_free(link);
        g_object_unref(object);
-       g_mutex_unlock(opengl->objects_lock);
        return object;
 }
 
@@ -445,33 +507,21 @@ static void _objects_free(gpointer value)
        g_free(level);
 }
 
-G_DEFINE_TYPE(GisOpenGL, gis_opengl, GIS_TYPE_VIEWER);
-static void gis_opengl_init(GisOpenGL *opengl)
+G_DEFINE_TYPE(GritsOpenGL, grits_opengl, GRITS_TYPE_VIEWER);
+static void grits_opengl_init(GritsOpenGL *opengl)
 {
-       g_debug("GisOpenGL: init");
+       g_debug("GritsOpenGL: init");
        opengl->objects      = g_tree_new_full(_objects_cmp, NULL, NULL, _objects_free);
        opengl->objects_lock = g_mutex_new();
        opengl->sphere       = roam_sphere_new(opengl);
        opengl->sphere_lock  = g_mutex_new();
-
-       /* Set OpenGL before "realize" */
-       GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(
-                       GDK_GL_MODE_RGBA   | GDK_GL_MODE_DEPTH |
-                       GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA);
-       if (!glconfig)
-               g_error("Failed to create glconfig");
-       if (!gtk_widget_set_gl_capability(GTK_WIDGET(opengl),
-                               glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
-               g_error("GL lacks required capabilities");
-       g_object_unref(glconfig);
-
-       /* Finish OpenGL init after it's realized */
+       gtk_gl_enable(GTK_WIDGET(opengl));
        g_signal_connect(opengl, "realize", G_CALLBACK(on_realize), NULL);
 }
-static void gis_opengl_dispose(GObject *_opengl)
+static void grits_opengl_dispose(GObject *_opengl)
 {
-       g_debug("GisOpenGL: dispose");
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_debug("GritsOpenGL: dispose");
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        if (opengl->sm_source[0]) {
                g_source_remove(opengl->sm_source[0]);
                opengl->sm_source[0] = 0;
@@ -484,30 +534,30 @@ static void gis_opengl_dispose(GObject *_opengl)
                g_source_remove(opengl->ue_source);
                opengl->ue_source = 0;
        }
-       G_OBJECT_CLASS(gis_opengl_parent_class)->dispose(_opengl);
+       G_OBJECT_CLASS(grits_opengl_parent_class)->dispose(_opengl);
 }
-static void gis_opengl_finalize(GObject *_opengl)
+static void grits_opengl_finalize(GObject *_opengl)
 {
-       g_debug("GisOpenGL: finalize");
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_debug("GritsOpenGL: finalize");
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        roam_sphere_free(opengl->sphere);
        g_tree_destroy(opengl->objects);
        g_mutex_free(opengl->objects_lock);
        g_mutex_free(opengl->sphere_lock);
-       G_OBJECT_CLASS(gis_opengl_parent_class)->finalize(_opengl);
+       G_OBJECT_CLASS(grits_opengl_parent_class)->finalize(_opengl);
 }
-static void gis_opengl_class_init(GisOpenGLClass *klass)
+static void grits_opengl_class_init(GritsOpenGLClass *klass)
 {
-       g_debug("GisOpenGL: class_init");
+       g_debug("GritsOpenGL: class_init");
        GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-       gobject_class->finalize = gis_opengl_finalize;
-       gobject_class->dispose = gis_opengl_dispose;
-
-       GisViewerClass *viewer_class = GIS_VIEWER_CLASS(klass);
-       viewer_class->center_position   = gis_opengl_center_position;
-       viewer_class->project           = gis_opengl_project;
-       viewer_class->clear_height_func = gis_opengl_clear_height_func;
-       viewer_class->set_height_func   = gis_opengl_set_height_func;
-       viewer_class->add               = gis_opengl_add;
-       viewer_class->remove            = gis_opengl_remove;
+       gobject_class->finalize = grits_opengl_finalize;
+       gobject_class->dispose = grits_opengl_dispose;
+
+       GritsViewerClass *viewer_class = GRITS_VIEWER_CLASS(klass);
+       viewer_class->center_position   = grits_opengl_center_position;
+       viewer_class->project           = grits_opengl_project;
+       viewer_class->clear_height_func = grits_opengl_clear_height_func;
+       viewer_class->set_height_func   = grits_opengl_set_height_func;
+       viewer_class->add               = grits_opengl_add;
+       viewer_class->remove            = grits_opengl_remove;
 }