]> Pileus Git - grits/blobdiff - src/gis-opengl.c
Update copyright and email address
[grits] / src / gis-opengl.c
index b07820612d1d6f7b25d53b2e7ee8d7278a0f74e9..9a88896eccb5d67e3b2c9da580cf7c684157d5b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -88,7 +88,7 @@ static void _set_visuals(GisOpenGL *self)
 
        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.0, 0.0, 0.0, 1.0};
+       float material_specular[] = {0.1, 0.1, 0.1, 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);
@@ -102,12 +102,6 @@ static void _set_visuals(GisOpenGL *self)
        glRotatef(lat, 1, 0, 0);
        glRotatef(-lon, 0, 1, 0);
 
-       /* Misc */
-       gdouble rg   = MAX(0, 1-(elev/20000));
-       gdouble blue = MAX(0, 1-(elev/50000));
-       glClearColor(MIN(0.65,rg), MIN(0.65,rg), MIN(1,blue), 1.0f);
-       glColor4f(1, 1, 1, 1);
-
        glDisable(GL_ALPHA_TEST);
 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -270,7 +264,9 @@ static void on_realize(GisOpenGL *self, gpointer _)
 {
        g_debug("GisOpenGL: on_realize");
        _set_visuals(self);
+       g_mutex_lock(self->sphere_lock);
        roam_sphere_update_errors(self->sphere);
+       g_mutex_unlock(self->sphere_lock);
 }
 static gboolean on_configure(GisOpenGL *self, GdkEventConfigure *event, gpointer _)
 {
@@ -288,7 +284,9 @@ static gboolean on_configure(GisOpenGL *self, GdkEventConfigure *event, gpointer
        gluPerspective(rad2deg(ang)*2, width/height, 1, 10*EARTH_R);
 
 #ifndef ROAM_DEBUG
+       g_mutex_lock(self->sphere_lock);
        roam_sphere_update_errors(self->sphere);
+       g_mutex_unlock(self->sphere_lock);
 #endif
 
        _gis_opengl_end(self);
@@ -311,7 +309,8 @@ static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
 
        /* Freeze depth buffer and draw transparent objects sorted */
        /* TODO: sorting */
-       glDepthMask(FALSE);
+       //glDepthMask(FALSE);
+       glAlphaFunc(GL_GREATER, 0.1);
        for (cur = level->sorted.next; cur; cur = cur->next, nsorted++)
                _draw_object(self, GIS_OBJECT(cur->data));
 
@@ -402,8 +401,10 @@ static gboolean on_idle(GisOpenGL *self)
        //g_debug("GisOpenGL: on_idle");
        gdk_threads_enter();
        _gis_opengl_begin(self);
+       g_mutex_lock(self->sphere_lock);
        if (roam_sphere_split_merge(self->sphere))
                gtk_widget_queue_draw(GTK_WIDGET(self));
+       g_mutex_unlock(self->sphere_lock);
        _gis_opengl_end(self);
        gdk_threads_leave();
        return TRUE;
@@ -475,12 +476,30 @@ static void gis_opengl_render_tile(GisViewer *_self, GisTile *tile)
                gdouble londist = e - w;
                gdouble latdist = n - s;
 
-               gdouble xy[][3] = {
+               gdouble xy[3][2] = {
                        {(lon[0]-w)/londist, 1-(lat[0]-s)/latdist},
                        {(lon[1]-w)/londist, 1-(lat[1]-s)/latdist},
                        {(lon[2]-w)/londist, 1-(lat[2]-s)/latdist},
                };
 
+               //if ((lat[0] == 90 && (xy[0][0] < 0 || xy[0][0] > 1)) ||
+               //    (lat[1] == 90 && (xy[1][0] < 0 || xy[1][0] > 1)) ||
+               //    (lat[2] == 90 && (xy[2][0] < 0 || xy[2][0] > 1)))
+               //      g_message("w,e=%4.f,%4.f   "
+               //                "lat,lon,x,y="
+               //                "%4.1f,%4.0f,%4.2f,%4.2f   "
+               //                "%4.1f,%4.0f,%4.2f,%4.2f   "
+               //                "%4.1f,%4.0f,%4.2f,%4.2f   ",
+               //              w,e,
+               //              lat[0], lon[0], xy[0][0], xy[0][1],
+               //              lat[1], lon[1], xy[1][0], xy[1][1],
+               //              lat[2], lon[2], xy[2][0], xy[2][1]);
+
+               /* Fix poles */
+               if (lat[0] == 90 || lat[0] == -90) xy[0][0] = 0.5;
+               if (lat[1] == 90 || lat[1] == -90) xy[1][0] = 0.5;
+               if (lat[2] == 90 || lat[2] == -90) xy[2][0] = 0.5;
+
                glEnable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D, *(guint*)tile->data);
                glBegin(GL_TRIANGLES);
@@ -517,6 +536,7 @@ static void gis_opengl_set_height_func(GisViewer *_self, GisTile *tile,
        if (!tile)
                return;
        /* TODO: get points? */
+       g_mutex_lock(self->sphere_lock);
        GList *triangles = roam_sphere_get_intersect(self->sphere, TRUE,
                        tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
        for (GList *cur = triangles; cur; cur = cur->next) {
@@ -532,6 +552,7 @@ static void gis_opengl_set_height_func(GisViewer *_self, GisTile *tile,
                }
        }
        g_list_free(triangles);
+       g_mutex_unlock(self->sphere_lock);
 }
 
 static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
@@ -627,6 +648,7 @@ static void gis_opengl_init(GisOpenGL *self)
 
        self->objects = g_tree_new(_objects_cmp);
        self->sphere = roam_sphere_new(self);
+       self->sphere_lock = g_mutex_new();
 
 #ifndef ROAM_DEBUG
        self->sm_source[0] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+30, 33,  (GSourceFunc)on_idle, self, NULL);
@@ -654,10 +676,6 @@ static void gis_opengl_dispose(GObject *_self)
                g_source_remove(self->sm_source[1]);
                self->sm_source[1] = 0;
        }
-       if (self->sphere) {
-               roam_sphere_free(self->sphere);
-               self->sphere = NULL;
-       }
        /* TODO: Cleanup/free objects tree */
        G_OBJECT_CLASS(gis_opengl_parent_class)->dispose(_self);
 }
@@ -665,13 +683,15 @@ static void gis_opengl_finalize(GObject *_self)
 {
        g_debug("GisViewer: finalize");
        GisOpenGL *self = GIS_OPENGL(_self);
+       roam_sphere_free(self->sphere);
+       g_mutex_free(self->sphere_lock);
        G_OBJECT_CLASS(gis_opengl_parent_class)->finalize(_self);
 }
 static void gis_opengl_class_init(GisOpenGLClass *klass)
 {
        g_debug("GisOpenGL: class_init");
        GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-       gobject_class->dispose     = gis_opengl_dispose;
+       gobject_class->dispose = gis_opengl_dispose;
 
        GisViewerClass *viewer_class = GIS_VIEWER_CLASS(klass);
        viewer_class->center_position   = gis_opengl_center_position;