Index: /issm/trunk-jpl/src/m/plot/plot_unit.js
===================================================================
--- /issm/trunk-jpl/src/m/plot/plot_unit.js	(revision 19726)
+++ /issm/trunk-jpl/src/m/plot/plot_unit.js	(revision 19727)
@@ -9,4 +9,23 @@
 	//edgecolor
 	edgecolor=options.getfieldvalue('edgecolor','none');
+	
+	/*First initialize webgl for the corresponding canvas: */
+	var canvas=document.getElementById(options.getfieldvalue('canvasid'));
+
+	//Initialize the GL context: 
+	var gl=initWebGL(canvas);
+
+	// Only continue if WebGL is available and working
+
+	if (gl) {
+		// Set clear color to black, fully opaque
+		gl.clearColor(0.0, 0.0, 0.0, 1.0);
+		// Enable depth testing
+		gl.enable(gl.DEPTH_TEST);
+		// Near things obscure far things
+		gl.depthFunc(gl.LEQUAL);
+		// Clear the color as well as the depth buffer.
+		gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+	}
 
 	switch(datatype){
@@ -42,6 +61,4 @@
 		case 2:
 
-			
-
 			if (elements[0].length==6){ //prisms
 				/*A=elements(:,1); B=elements(:,2); C=elements(:,3); D=elements(:,4); E=elements(:,5); F=elements(:,6);
@@ -60,22 +77,4 @@
 			}
 			else{
-				
-				var canvas=document.getElementById(options.getfieldvalue('canvasid'));
-
-				//Initialize the GL context: 
-				var gl=initWebGL(canvas);
-
-				// Only continue if WebGL is available and working
-
-				if (gl) {
-					// Set clear color to black, fully opaque
-					gl.clearColor(0.0, 0.0, 0.0, 1.0);
-					// Enable depth testing
-					gl.enable(gl.DEPTH_TEST);
-					// Near things obscure far things
-					gl.depthFunc(gl.LEQUAL);
-					// Clear the color as well as the depth buffer.
-					gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
-				}
 				
 				/*A=elements(:,1); B=elements(:,2); C=elements(:,3); 
Index: /issm/trunk-jpl/src/m/plot/webgl.js
===================================================================
--- /issm/trunk-jpl/src/m/plot/webgl.js	(revision 19726)
+++ /issm/trunk-jpl/src/m/plot/webgl.js	(revision 19727)
@@ -1,3 +1,4 @@
-function initWebGL(canvas) {
+/*This is where we have all our webgl relevant functionality for the plotting routines: */
+function initWebGL(canvas) { //{{{
 	gl = null;
 
@@ -15,3 +16,3 @@
 
 	return gl;
-}
+} //}}}
