+enum {
+ LAYER_TOPO,
+ LAYER_COUNTY,
+ LAYER_RIVERS,
+ LAYER_HIGHWAYS,
+ LAYER_CITY,
+ LAYER_COUNT
+};
+
+static struct {
+ char *fmt;
+ float z;
+ guint tex;
+} layers[] = {
+ [LAYER_TOPO] = { "Overlays/" "Topo/" "Short/" "%s_Topo_Short.jpg", 1.0, 0 },
+ [LAYER_COUNTY] = { "Overlays/" "County/" "Short/" "%s_County_Short.gif", 3.0, 0 },
+ [LAYER_RIVERS] = { "Overlays/" "Rivers/" "Short/" "%s_Rivers_Short.gif", 4.0, 0 },
+ [LAYER_HIGHWAYS] = { "Overlays/" "Highways/" "Short/" "%s_Highways_Short.gif", 5.0, 0 },
+ [LAYER_CITY] = { "Overlays/" "Cities/" "Short/" "%s_City_Short.gif", 6.0, 0 },
+};
+
+static CURL *curl_handle;
+
+
+/**
+ * Cache a image from Ridge to the local disk
+ * \param path Path to the Ridge file, starting after /ridge/
+ * \return The local path to the cached image
+ */
+char *cache_image(char *path)
+{
+ gchar base[] = "http://radar.weather.gov/ridge/";
+ gchar *url = g_strconcat(base, path, NULL);
+ gchar *local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL);
+ if (!g_file_test(local, G_FILE_TEST_EXISTS)) {
+ if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) {
+ //g_printerr("Making directory %s\n", g_path_get_dirname(local));
+ g_mkdir_with_parents(g_path_get_dirname(local), 0755);
+ }
+ //g_printerr("Fetching image %s -> %s\n", url, local);
+ long http_code;
+ FILE *cached_image = fopen(local, "w+");
+ curl_easy_setopt(curl_handle, CURLOPT_URL, url);
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, cached_image);
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, NULL);
+ curl_easy_perform(curl_handle);
+ curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
+ fflush(cached_image);
+ if (http_code != 200) {
+ g_message("http %ld while fetching %s", http_code, url);
+ remove(local);
+ return NULL;
+ }
+ }
+ return local;
+}
+
+/**
+ * Load an image into an OpenGL texture
+ * \param filename Path to the image file
+ * \return The OpenGL identifier for the texture
+ */