<p><b>dwj07@fsu.edu</b> 2012-10-22 14:54:30 -0600 (Mon, 22 Oct 2012)</p><p><br>
        -- BRANCH COMMIT --<br>
<br>
        Adding functionality to mpas_draw:<br>
                Adding the q and S keys to available keys.<br>
                q takes a screenshot.<br>
                S turns on and off the interior sphere.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/tools/mpas_draw/README
===================================================================
--- branches/tools/mpas_draw/README        2012-10-22 19:54:16 UTC (rev 2245)
+++ branches/tools/mpas_draw/README        2012-10-22 20:54:30 UTC (rev 2246)
@@ -75,6 +75,13 @@
                        1-9: 10*Number Pressed% of Color range (eg. 10% = 1, 20% = 2...)
                        0: 100% of Color range
+                q:
+                        The lowercase q key saves the current buffer as a screenshot to ss.tga. You can afterwards convert the .tga file to any format.
+
+                S: (sphere)
+                        The uppercase S key turns on and off the background sphere (only if the file is defined on a sphere).
+                        This is useful for looking at where land is in a spherical mesh.
+
                ESC:
                        The escape key closes the program.
Modified: branches/tools/mpas_draw/mpas_draw.cpp
===================================================================
--- branches/tools/mpas_draw/mpas_draw.cpp        2012-10-22 19:54:16 UTC (rev 2245)
+++ branches/tools/mpas_draw/mpas_draw.cpp        2012-10-22 20:54:30 UTC (rev 2246)
@@ -64,15 +64,18 @@
void drawSphere(double r, int lats, int longs);
+void screenshot (char filename[160],int x, int y) ;
+
//
// Global data.
//
string filename;
static GLint axis = 1;
GLint window;
-int drawing = 0;
+int drawing = 1;
int draw_lines = 1;
bool on_sphere;
+bool draw_sphere;
double sphere_radius;
int color_bar = 0;
double missing_value = -1e34;
@@ -88,8 +91,8 @@
double projLeftRight = 0.0;
double projDistance        = 3.0;
double projTwist                = 0.0;
-double projElevation        = 0.0;
-double projAzimuth                = 0.0;
+double projElevation        = 90.0;
+double projAzimuth                = -90.0;
bool spinning = false;
static GLfloat theta[3] = { 0.0, 0.0, 0.0 };
@@ -255,6 +258,7 @@
        glutMainLoop ( );
+
        //
        // Things that won't actually happen because we never return from glutMainLoop:
        //
@@ -305,7 +309,7 @@
        translateView ( projUpDown, projLeftRight );
        polarView( projDistance, projTwist, projElevation, projAzimuth );
-        if(on_sphere){
+        if(on_sphere && draw_sphere){
                drawSphere(0.989, 40, 40);
        }
@@ -344,7 +348,6 @@
        //
        glutSwapBuffers ( );
-
        return;
}/*}}}*/
void mouse ( int btn, int state, int x, int y ){/*{{{*/
@@ -652,6 +655,7 @@
        maxedges = netcdf_mpas_read_dim(filename, "maxEdges");
        on_sphere = netcdf_mpas_read_onsphere(filename);
        sphere_radius = netcdf_mpas_read_sphereradius(filename);
+        draw_sphere = false;
        cell_cells.reserve((ncells+1)*maxedges*3*3);
        cell_lines.reserve((ncells+1)*maxedges*3*2);
@@ -1115,6 +1119,7 @@
        delete [] xvertex;
        delete [] yvertex;
        delete [] zvertex;
+
}/*}}}*/
void setup_ranges(){/*{{{*/
        int num_vars;
@@ -1264,13 +1269,15 @@
                xyz_center[i] = ( xyz_min[i] + xyz_max[i] ) / 2.0;
                xyz_scale = std::max ( xyz_scale, ( xyz_max[i] - xyz_min[i] ) / 2.0 );
        }
-
+/*
        if(on_sphere){
                xyz_scale = sphere_radius;
                xyz_center[0] = 0.0;
                xyz_center[1] = 0.0;
                xyz_center[2] = 0.0;
-        }
+
+                cout << "Rescaling.... radius = " << xyz_scale << endl;
+        }*/
        //
        // A sphere doesn't need this rescaling.
        // A box does!
@@ -2160,6 +2167,12 @@
                        range_factor = 0.9;
                        color_mesh();
                        break;
+                case KEY_S:
+                        draw_sphere = !draw_sphere;
+                        break;
+                case KEY_q:
+                        screenshot("ss.tga", 800, 800);
+                        break;
                default:
                        break;
        }
@@ -2329,3 +2342,28 @@
                glEnd();
        }
}/*}}}*/
+
+void screenshot (char filename[160],int x, int y) /*{{{*/
+{// get the image data
+        long imageSize = x * y * 3;
+        unsigned char *data = new unsigned char[imageSize];
+        glReadPixels(0,0,x,y, GL_BGR,GL_UNSIGNED_BYTE,data);// split x and y sizes into bytes
+        int xa= x % 256;
+        int xb= (x-xa)/256;
+        int ya= y % 256;
+        int yb= (y-ya)/256;
+
+        //assemble the header
+        unsigned char header[18]={0,0,2,0,0,0,0,0,0,0,0,0,(char)xa,(char)xb,(char)ya,(char)yb,24,0};
+
+        // write header and data to file
+        fstream File(filename, ios::out | ios::binary);
+        File.write (reinterpret_cast<char *>(header), sizeof (char)*18);
+        File.write (reinterpret_cast<char *>(data), sizeof (char)*imageSize);
+        File.close();
+
+        delete[] data;
+        data=NULL;
+
+        cout << "Screenshot written to: ss.tga" << endl;
+}/*}}}*/
</font>
</pre>