+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ /* Camera 1 */
+ double lat, lon, elev, rx, ry, rz;
+ gis_viewer_get_location(GIS_VIEWER(self), &lat, &lon, &elev);
+ gis_viewer_get_rotation(GIS_VIEWER(self), &rx, &ry, &rz);
+ glRotatef(rx, 1, 0, 0);
+ glRotatef(rz, 0, 0, 1);
+
+ /* Lighting */
+#ifdef ROAM_DEBUG
+ float light_ambient[] = {0.7f, 0.7f, 0.7f, 1.0f};
+ 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};
+#endif
+ float light_position[] = {-13*EARTH_R, 1*EARTH_R, 3*EARTH_R, 1.0f};
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+ 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_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);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_emission);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_COLOR_MATERIAL);
+
+ /* Camera 2 */
+ glTranslatef(0, 0, -elev2rad(elev));
+ glRotatef(lat, 1, 0, 0);
+ glRotatef(-lon, 0, 1, 0);
+
+ glDisable(GL_ALPHA_TEST);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+#ifndef ROAM_DEBUG
+ glCullFace(GL_BACK);
+ glEnable(GL_CULL_FACE);
+#endif
+
+ glClearDepth(1.0);
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+
+ glEnable(GL_LINE_SMOOTH);
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ //glShadeModel(GL_FLAT);
+
+ roam_sphere_update_view(self->sphere);
+}
+
+
+/********************
+ * Object handleing *
+ ********************/
+static void _draw_tile(GisOpenGL *self, GisTile *tile)
+{
+ if (!tile || !tile->data)
+ return;
+ GList *triangles = roam_sphere_get_intersect(self->sphere, FALSE,
+ tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
+ if (!triangles)
+ g_warning("GisOpenGL: _draw_tiles - No triangles to draw: edges=%f,%f,%f,%f",
+ tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
+ //g_message("drawing %4d triangles for tile edges=%7.2f,%7.2f,%7.2f,%7.2f",
+ // g_list_length(triangles), tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
+ for (GList *cur = triangles; cur; cur = cur->next) {
+ RoamTriangle *tri = cur->data;
+
+ gdouble lat[3] = {tri->p.r->lat, tri->p.m->lat, tri->p.l->lat};
+ gdouble lon[3] = {tri->p.r->lon, tri->p.m->lon, tri->p.l->lon};
+
+ if (lon[0] < -90 || lon[1] < -90 || lon[2] < -90) {
+ if (lon[0] > 90) lon[0] -= 360;
+ if (lon[1] > 90) lon[1] -= 360;
+ if (lon[2] > 90) lon[2] -= 360;
+ }
+
+ gdouble n = tile->edge.n;
+ gdouble s = tile->edge.s;
+ gdouble e = tile->edge.e;
+ gdouble w = tile->edge.w;
+
+ gdouble londist = e - w;
+ gdouble latdist = n - s;
+
+ 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);
+ glNormal3dv(tri->p.r->norm); glTexCoord2dv(xy[0]); glVertex3dv((double*)tri->p.r);
+ glNormal3dv(tri->p.m->norm); glTexCoord2dv(xy[1]); glVertex3dv((double*)tri->p.m);
+ glNormal3dv(tri->p.l->norm); glTexCoord2dv(xy[2]); glVertex3dv((double*)tri->p.l);
+ glEnd();