trying to get z-ordering working
authorAndy Spencer <andy753421@gmail.com>
Wed, 6 May 2009 08:09:21 +0000 (08:09 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 6 May 2009 08:09:21 +0000 (08:09 +0000)
src/aweather.c
src/example.c
src/opengl.c
src/radar.c
src/ridge.c

index 22479bf..380db65 100644 (file)
@@ -59,9 +59,14 @@ int main(int argc, char *argv[])
        GtkWidget *drawing = gtk_drawing_area_new();
        gtk_paned_pack1(GTK_PANED(paned), drawing, TRUE, FALSE);
        //gtk_box_pack_end(GTK_BOX(vbox), drawing, TRUE, TRUE, 0);
-       GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE);
-       if (!glconfig) g_assert_not_reached();
-       if (!gtk_widget_set_gl_capability(drawing, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE)) g_assert_not_reached();
+       GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(
+                       GDK_GL_MODE_RGBA |
+                       GDK_GL_MODE_DEPTH |
+                       GDK_GL_MODE_DOUBLE);
+       if (!glconfig)
+               g_assert_not_reached();
+       if (!gtk_widget_set_gl_capability(drawing, glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
+               g_assert_not_reached();
 
        /* Set up tab area */
        GtkWidget *tab_area = gtk_notebook_new();
@@ -75,7 +80,7 @@ int main(int argc, char *argv[])
        opengl_init (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area));
        ridge_init  (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area));
        radar_init  (GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area));
-       example_init(GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area));
+       //example_init(GTK_DRAWING_AREA(drawing), GTK_NOTEBOOK(tab_area));
 
        gtk_widget_show_all(window);
        gtk_main();
index ffadee5..22b90ff 100644 (file)
@@ -22,7 +22,6 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
        glEnable(GL_COLOR_MATERIAL);
-       glEnable(GL_DEPTH_TEST);
 
        glRotatef(ang, 1, 0, 1);
        glColor3f(0.9, 0.9, 0.7);
@@ -33,7 +32,6 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
        glDisable(GL_LIGHT0);
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
-       glDisable(GL_DEPTH_TEST);
 
        glPopMatrix();
        return FALSE;
index 09b41d5..c943c79 100644 (file)
@@ -22,9 +22,9 @@ static gboolean expose_start(GtkWidget *da, GdkEventExpose *event, gpointer user
 /* Plugins run stuff here */
 static gboolean expose_end(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
 {
-       g_message("opengl:expose_end");
+       g_message("opengl:expose_end\n");
 
-       GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
+       GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current();
 
        if (gdk_gl_drawable_is_double_buffered(gldrawable))
                gdk_gl_drawable_swap_buffers(gldrawable);
@@ -47,27 +47,38 @@ static gboolean configure_start(GtkWidget *da, GdkEventConfigure *event, gpointe
        double width  = da->allocation.width;
        double height = da->allocation.height;
        double dist   = 500*1000; // 500 km
-       glViewport(0, 0, width, height);
 
+       /* Misc */
+       glViewport(0, 0, width, height);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glClearColor(0.8f, 0.8f, 1.0f, 0.0f);
+       glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
 
+       /* Depth test */
+       glClearDepth(1.0);
+       glDepthFunc(GL_LEQUAL);
+       glEnable(GL_DEPTH_TEST);
+
+       /* Perspective */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        double rad = atan(height/2*1000.0/dist); // 1px = 1000 meters
        double deg = (rad*180)/M_PI;
-       gluPerspective(deg*2, width/height, 0.1f, 10000000.0f);
+       gluPerspective(deg*2, width/height, 0.1f, 1000000000.0f);
 
+       /* Camera position? */
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.0, 0.0, -dist);
-       glRotatef(-45, 1, 0, 0);
+       //glRotatef(-45, 1, 0, 0);
+
 
        return FALSE;
 }
 static gboolean configure_end(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
 {
-       GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
+       GdkGLDrawable *gldrawable = gdk_gl_drawable_get_current();
        gdk_gl_drawable_gl_end(gldrawable);
        return FALSE;
 }
index 8881662..5eda980 100644 (file)
@@ -109,17 +109,15 @@ static gboolean configure(GtkWidget *da, GdkEventConfigure *event, gpointer user
 
 static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
 {
-       glPushMatrix();
-       glMatrixMode(GL_MODELVIEW);
-       glTranslatef(0, 0, 100000);
-
-       //g_message("radar:expose");
+       g_message("radar:expose");
        Sweep *sweep = cur_sweep;
 
        /* Draw the rays */
+
+       glPushMatrix();
        glBindTexture(GL_TEXTURE_2D, sweep_tex);
        glEnable(GL_TEXTURE_2D);
-
+       glColor3f(1,1,1);
        glBegin(GL_QUAD_STRIP);
        int _ri; // not really used, creates strange fragments..
        for (_ri = 0; _ri < sweep->h.nrays; _ri++) {
@@ -140,15 +138,15 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
                /* (find middle of bin) / scale for opengl */
                // near left
                glTexCoord2f(0.0, (double)ri/sweep->h.nrays);
-               glVertex3f(lx*near_dist, ly*near_dist, 2.0);
+               glVertex3f(lx*near_dist, ly*near_dist, 1.0);
 
                // far  left
                glTexCoord2f(1.0, (double)ri/sweep->h.nrays);
-               glVertex3f(lx*far_dist,  ly*far_dist,  2.0);
+               glVertex3f(lx*far_dist,  ly*far_dist,  1.0);
        }
        //g_print("ri=%d, nr=%d, bw=%f\n", _ri, sweep->h.nrays, sweep->h.beam_width);
        glEnd();
-       glPushMatrix();
+       glPopMatrix();
 
        /* Texture debug */
        //glBegin(GL_QUADS);
@@ -159,17 +157,18 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
        //glEnd();
 
        /* Print the color table */
-       glDisable(GL_TEXTURE_2D);
        glPushMatrix();
-       glLoadIdentity();
+       glDisable(GL_TEXTURE_2D);
+       glMatrixMode(GL_MODELVIEW ); glLoadIdentity();
+       glMatrixMode(GL_PROJECTION); glLoadIdentity();
        glBegin(GL_QUADS);
        int i;
        for (i = 0; i < nred; i++) {
                glColor4ub(red[i], green[i], blue[i], get_alpha(i));
-               glVertex3f(-1., (float)((i  ) - nred/2)/(nred/2), 2.); // bot left
-               glVertex3f(-1., (float)((i+1) - nred/2)/(nred/2), 2.); // top left
-               glVertex3f(-.9, (float)((i+1) - nred/2)/(nred/2), 2.); // top right
-               glVertex3f(-.9, (float)((i  ) - nred/2)/(nred/2), 2.); // bot right
+               glVertex3f(-1.0, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot left
+               glVertex3f(-1.0, (float)((i+1) - nred/2)/(nred/2), 0.0); // top left
+               glVertex3f(-0.9, (float)((i+1) - nred/2)/(nred/2), 0.0); // top right
+               glVertex3f(-0.9, (float)((i  ) - nred/2)/(nred/2), 0.0); // bot right
        }
        glEnd();
        glPopMatrix();
index 002970b..d7c204a 100644 (file)
@@ -19,11 +19,11 @@ static struct {
        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 },
+       [LAYER_TOPO]     = { "Overlays/" "Topo/"     "Short/" "%s_Topo_Short.jpg",     1, 0 },
+       [LAYER_COUNTY]   = { "Overlays/" "County/"   "Short/" "%s_County_Short.gif",   3, 0 },
+       [LAYER_RIVERS]   = { "Overlays/" "Rivers/"   "Short/" "%s_Rivers_Short.gif",   4, 0 },
+       [LAYER_HIGHWAYS] = { "Overlays/" "Highways/" "Short/" "%s_Highways_Short.gif", 5, 0 },
+       [LAYER_CITY]     = { "Overlays/" "Cities/"   "Short/" "%s_City_Short.gif",     6, 0 },
 };
 
 static CURL *curl_handle;
@@ -97,12 +97,11 @@ static gboolean expose(GtkWidget *da, GdkEventExpose *event, gpointer user_data)
 {
        g_message("ridge:expose");
        glPushMatrix();
-       //glScaled(500*1000, 500*1000, 0);
-       //glTranslatef(0,50000,5000);
+       glEnable(GL_TEXTURE_2D);
+       glColor3f(1,1,1);
 
        for (int i = 0; i < LAYER_COUNT; i++) {
                glBindTexture(GL_TEXTURE_2D, layers[i].tex);
-               glEnable(GL_TEXTURE_2D);
 
                glBegin(GL_POLYGON);
                glTexCoord2f(0.0, 0.0); glVertex3f(500*1000*-1.0, 500*1000* 1.0, layers[i].z);