+
+ roam_sphere_update_view(self->sphere);
+}
+
+
+/********************
+ * Object handleing *
+ ********************/
+static void _draw_marker(GisOpenGL *self, GisMarker *marker)
+{
+ GisPoint *point = gis_object_center(GIS_OBJECT(marker));
+ gdouble px, py, pz;
+ gis_viewer_project(GIS_VIEWER(self),
+ point->lat, point->lon, point->elev,
+ &px, &py, &pz);
+ if (pz > 1)
+ return;
+
+ //g_debug("GisOpenGL: draw_marker - %s pz=%f ", marker->label, pz);
+
+ cairo_surface_t *surface = cairo_get_target(marker->cairo);
+ gdouble width = cairo_image_surface_get_width(surface);
+ gdouble height = cairo_image_surface_get_height(surface);
+
+ glMatrixMode(GL_PROJECTION); glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW); glLoadIdentity();
+ glOrtho(0, GTK_WIDGET(self)->allocation.width,
+ 0, GTK_WIDGET(self)->allocation.height, -1, 1);
+ glTranslated(px - marker->xoff,
+ py - marker->yoff, 0);
+
+ glDisable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, marker->tex);
+ glBegin(GL_QUADS);
+ glTexCoord2f(1, 1); glVertex3f(width, 0 , 0);
+ glTexCoord2f(1, 0); glVertex3f(width, height, 0);
+ glTexCoord2f(0, 0); glVertex3f(0 , height, 0);
+ glTexCoord2f(0, 1); glVertex3f(0 , 0 , 0);
+ glEnd();
+}
+
+static void _draw_callback(GisOpenGL *self, GisCallback *callback)
+{
+ callback->callback(callback, callback->user_data);
+}
+
+static void _draw_object(GisOpenGL *self, GisObject *object)
+{
+ //g_debug("GisOpenGL: draw_object");
+ /* Skip out of range objects */
+ if (object->lod > 0) {
+ gdouble eye[3], obj[3];
+ gis_viewer_get_location(GIS_VIEWER(self), &eye[0], &eye[1], &eye[2]);
+ lle2xyz(eye[0], eye[1], eye[2], &eye[0], &eye[1], &eye[2]);
+ lle2xyz(object->center.lat, object->center.lon, object->center.elev,
+ &obj[0], &obj[1], &obj[2]);
+ gdouble dist = distd(obj, eye);
+ if (object->lod < dist)
+ return;
+ }
+
+ /* Draw */
+ glMatrixMode(GL_PROJECTION); glPushMatrix();
+ glMatrixMode(GL_MODELVIEW); glPushMatrix();
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
+ if (GIS_IS_MARKER(object)) {
+ _draw_marker(self, GIS_MARKER(object));
+ } else if (GIS_IS_CALLBACK(object)) {
+ _draw_callback(self, GIS_CALLBACK(object));
+ }
+ glPopAttrib();
+ glMatrixMode(GL_PROJECTION); glPopMatrix();
+ glMatrixMode(GL_MODELVIEW); glPopMatrix();
+}
+
+static void _load_object(GisOpenGL *self, GisObject *object)
+{
+ g_debug("GisOpenGL: load_object");
+ if (GIS_IS_MARKER(object)) {
+ GisMarker *marker = GIS_MARKER(object);
+ cairo_surface_t *surface = cairo_get_target(marker->cairo);
+ gdouble width = cairo_image_surface_get_width(surface);
+ gdouble height = cairo_image_surface_get_height(surface);
+
+ _gis_opengl_begin(self);
+ glEnable(GL_TEXTURE_2D);
+ glGenTextures(1, &marker->tex);
+ glBindTexture(GL_TEXTURE_2D, marker->tex);
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+ cairo_image_surface_get_data(surface));
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ g_debug("load_texture: %d", marker->tex);
+ _gis_opengl_end(self);
+ }
+}
+
+static void _unload_object(GisOpenGL *self, GisObject *object)
+{
+ g_debug("GisOpenGL: unload_object");
+ if (GIS_IS_MARKER(object)) {
+ GisMarker *marker = GIS_MARKER(object);
+ g_debug("delete_texture: %d", marker->tex);
+ glDeleteTextures(1, &marker->tex);
+ }