Index: trunk/packages/vizservers/nanovis/Trace.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/Trace.cpp	(revision 1195)
+++ trunk/packages/vizservers/nanovis/Trace.cpp	(revision 1196)
@@ -2,4 +2,7 @@
 #include <stdio.h>
 #include <stdarg.h>
+
+#include <GL/glew.h>
+#include <GL/glut.h>
 
 void Trace(const char* format, ...)
@@ -15,2 +18,74 @@
 }
 
+void 
+CheckFramebuffer(const char *string) 
+{
+  fprintf(stderr, "FB Status: %s: ", string);
+  GLenum status = (GLenum)glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+  switch(status) {
+    case GL_FRAMEBUFFER_COMPLETE_EXT:
+      fprintf(stderr, "<<<< OK >>>>\n");
+      break;
+    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n");
+      break;
+    case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");
+      break;
+    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n");
+      break;
+    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n");
+      break;
+    case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n");
+      break;
+    case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n");
+      break;
+    case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
+      fprintf(stderr, "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n");
+      break;
+    default:
+      fprintf(stderr, "UNKNOWN framebuffer status %d\n", status);
+  }
+}
+
+bool
+CheckGL(const char *string)
+{
+  fprintf(stderr, "GL Status: %s: ", string);
+  GLenum status = (GLenum)glGetError();
+  switch(status) {
+    case GL_NO_ERROR:
+      fprintf(stderr, "OK\n");
+      return true;
+    case GL_INVALID_ENUM:
+      fprintf(stderr, "GL_INVALID_ENUM\n");
+      break;
+    case GL_INVALID_VALUE:
+      fprintf(stderr, "GL_INVALID_VALUE\n");
+      break;
+    case GL_INVALID_OPERATION:
+      fprintf(stderr, "GL_INVALID_OPERATION\n");
+      break;
+    case GL_STACK_OVERFLOW:
+      fprintf(stderr, "GL_STACK_OVERFLOW\n");
+      break;
+    case GL_STACK_UNDERFLOW:
+      fprintf(stderr, "GL_STACK_UNDERFLOW\n");
+      break;
+    case GL_OUT_OF_MEMORY:
+      fprintf(stderr, "GL_OUT_OF_MEMORY\n");
+      break;
+    case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
+      fprintf(stderr, "GL_INVALID_FRAMEBUFFER_OPERATION_EXT\n");
+      break;
+    default:
+      fprintf(stderr, "UNKNOWN GL status %d\n", status);
+  } 
+  return false;
+}
+
+
Index: trunk/packages/vizservers/nanovis/Trace.h
===================================================================
--- trunk/packages/vizservers/nanovis/Trace.h	(revision 1195)
+++ trunk/packages/vizservers/nanovis/Trace.h	(revision 1196)
@@ -3,4 +3,5 @@
 
 extern void Trace(const char* format, ...);
-
+extern void CheckFramebuffer(const char *string);
+extern bool CheckGL(const char *string);
 #endif
Index: trunk/packages/vizservers/nanovis/define.h
===================================================================
--- trunk/packages/vizservers/nanovis/define.h	(revision 1195)
+++ trunk/packages/vizservers/nanovis/define.h	(revision 1196)
@@ -36,4 +36,53 @@
 typedef GLuint NVISid;			//OpenGL identifier: unsigned int
 
+#define CHECK_FRAMEBUFFER_STATUS() \
+{ \
+ GLenum status;  \
+ status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);  \
+ fprintf(stderr, "%x\n", status); \
+ switch(status) {  \
+ case GL_FRAMEBUFFER_COMPLETE_EXT:  \
+   fprintf(stderr,"framebuffer complete!\n"); \
+   break;  \
+ case GL_FRAMEBUFFER_UNSUPPORTED_EXT:  \
+   fprintf(stderr,"framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT\n"); \
+    /* you gotta choose different formats */  \
+   assert(0);  \
+   break;  \
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:  \
+   fprintf(stderr,"framebuffer INCOMPLETE_ATTACHMENT\n"); \
+   break;  \
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:  \
+   fprintf(stderr,"framebuffer FRAMEBUFFER_MISSING_ATTACHMENT\n"); \
+   break;  \
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:  \
+   fprintf(stderr,"framebuffer FRAMEBUFFER_DIMENSIONS\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_FORMATS\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_DRAW_BUFFER\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_READ_BUFFER\n");\
+   break; \
+ case GL_FRAMEBUFFER_BINDING_EXT: \
+   fprintf(stderr,"framebuffer BINDING_EXT\n");\
+   break; \
+/* 
+ *  case GL_FRAMEBUFFER_STATUS_ERROR_EXT: \
+ *     fprintf(stderr,"framebuffer STATUS_ERROR\n");\
+ *        break; \
+ *        */ \
+ default: \
+   fprintf(stderr,"unknown framebuffer error %d\n", status);\
+   /* programming error; will fail on all hardware */ \
+   assert(0); \
+ }\
+}
+
+#ifdef notdef
+
 
 #define CHECK_FRAMEBUFFER_STATUS()                            \
@@ -53,4 +102,5 @@
      }	                                                      \
    }
+#endif
 
 // use this to send debug messages back to the client
Index: trunk/packages/vizservers/nanovis/global.h
===================================================================
--- trunk/packages/vizservers/nanovis/global.h	(revision 1195)
+++ trunk/packages/vizservers/nanovis/global.h	(revision 1196)
@@ -22,4 +22,54 @@
 #include <stdio.h>
 
+#ifdef notdef
+#define CHECK_FRAMEBUFFER_STATUS() \
+{\
+ GLenum status; \
+ status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); \
+ fprintf(stderr, "%x\n", status);\
+ switch(status) { \
+ case GL_FRAMEBUFFER_COMPLETE_EXT: \
+   fprintf(stderr,"framebuffer complete!\n");\
+   break; \
+ case GL_FRAMEBUFFER_UNSUPPORTED_EXT: \
+   fprintf(stderr,"framebuffer GL_FRAMEBUFFER_UNSUPPORTED_EXT\n");\
+    /* you gotta choose different formats */ \
+   assert(0); \
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_ATTACHMENT\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: \
+   fprintf(stderr,"framebuffer FRAMEBUFFER_MISSING_ATTACHMENT\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: \
+   fprintf(stderr,"framebuffer FRAMEBUFFER_DIMENSIONS\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_DUPLICATE_ATTACHMENT\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_FORMATS\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_DRAW_BUFFER\n");\
+   break; \
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: \
+   fprintf(stderr,"framebuffer INCOMPLETE_READ_BUFFER\n");\
+   break; \
+ case GL_FRAMEBUFFER_BINDING_EXT: \
+   fprintf(stderr,"framebuffer BINDING_EXT\n");\
+   break; \
+/* 
+ *  case GL_FRAMEBUFFER_STATUS_ERROR_EXT: \
+ *     fprintf(stderr,"framebuffer STATUS_ERROR\n");\
+ *        break; \
+ *        */ \
+ default: \
+   /* programming error; will fail on all hardware */ \
+   assert(0); \
+ }\
+}
+
 #define CHECK_FRAMEBUFFER_STATUS()                            \
   {                                                           \
@@ -38,5 +88,5 @@
      }	                                                      \
    }
-
+#endif
 
 inline void 
Index: trunk/packages/vizservers/nanovis/imgLoaders/BMPImageLoaderImpl.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/imgLoaders/BMPImageLoaderImpl.cpp	(revision 1195)
+++ trunk/packages/vizservers/nanovis/imgLoaders/BMPImageLoaderImpl.cpp	(revision 1196)
@@ -20,4 +20,5 @@
     Image* image = 0;
 
+    printf("opening image file \"%s\"\n", fileName);
     FILE* f = fopen(fileName, "rb");
 
Index: trunk/packages/vizservers/nanovis/nanovis.cpp
===================================================================
--- trunk/packages/vizservers/nanovis/nanovis.cpp	(revision 1195)
+++ trunk/packages/vizservers/nanovis/nanovis.cpp	(revision 1196)
@@ -42,4 +42,5 @@
 
 #include "nanovis.h"
+#include "define.h"
 #include "RpField1D.h"
 #include "RpFieldRect3D.h"
@@ -133,12 +134,17 @@
 
 //frame buffer for final rendering
-NVISid NanoVis::final_fbo = 0;
+char dummy0[2000];
 NVISid NanoVis::final_color_tex = 0;
 NVISid NanoVis::final_depth_rb = 0;
+char dummy1[2000];
+NVISid NanoVis::final_fbo = 0;
 int NanoVis::render_window = 0;       /* GLUT handle for the render window */
+char dummy2[2000];
 int NanoVis::win_width = NPIX;        /* Width of the render window */
 int NanoVis::win_height = NPIX;       /* Height of the render window */
 
+char dummy3[2000];
 unsigned char* NanoVis::screen_buffer = NULL;
+char dummy4[2000];
 
 /* FIXME: This variable is always true. */
@@ -166,5 +172,4 @@
 CGprogram m_passthru_fprog;
 CGparameter m_passthru_scale_param, m_passthru_bias_param;
-
 
 // Variables for mouse events
@@ -545,10 +550,10 @@
 
 int
-NanoVis::render_legend(
-    TransferFunction *tf,
-    double min, double max,
-    int width, int height,
-    const char* volArg)
-{
+NanoVis::render_legend(TransferFunction *tf, double min, double max,
+	    		int width, int height, const char* volArg)
+{
+    if (debug_flag) {
+    	fprintf(stderr, "in render_legend\n");
+    }
     int old_width = win_width;
     int old_height = win_height;
@@ -583,4 +588,7 @@
     resize_offscreen_buffer(old_width, old_height);
 
+    if (debug_flag) {
+    	fprintf(stderr, "leaving render_legend\n");
+    }
     return TCL_OK;
 }
@@ -590,5 +598,91 @@
 NanoVis::init_offscreen_buffer()
 {
-    //initialize final fbo for final display
+    if (debug_flag) {
+       fprintf(stderr, "in init_offscreen_buffer\n");
+    }
+   
+    glGenTextures(1, &final_color_tex);
+    glBindTexture(GL_TEXTURE_2D, final_color_tex);
+
+    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+#ifdef NV40
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0,
+                 GL_RGB, GL_INT, NULL);
+#else
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0,
+                 GL_RGBA, GL_INT, NULL);
+
+#endif
+    if (!CheckGL("glTexImage2D")) {
+        return;
+    }
+
+    glGenRenderbuffersEXT(1, &final_depth_rb);
+    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
+    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
+                             GL_DEPTH_COMPONENT24, win_width, win_height);
+
+    // Initialize a fbo for final display.
+    glGenFramebuffersEXT(1, &final_fbo);
+    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
+    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+                              GL_COLOR_ATTACHMENT0_EXT,
+                              GL_TEXTURE_2D, final_color_tex, 0);
+    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+                             GL_DEPTH_ATTACHMENT_EXT,
+                             GL_RENDERBUFFER_EXT, final_depth_rb);
+    CheckGL("glFramebufferTexture2DEXT");
+    CheckFramebuffer("final_fbo");
+
+
+    // Check framebuffer completeness at the end of initialization.
+    //CHECK_FRAMEBUFFER_STATUS();
+    //NanoVis::display();
+
+    //assert(glGetError()==0);
+    if (debug_flag) {
+       fprintf(stderr, "leaving init_offscreen_buffer\n");
+    }
+}
+
+
+//resize the offscreen buffer 
+void 
+NanoVis::resize_offscreen_buffer(int w, int h)
+{
+    if (debug_flag) {
+       fprintf(stderr, "in resize_offscreen_buffer(%d, %d)\n", w, h);
+    }
+    win_width = w;
+    win_height = h;
+
+    if (fonts) {
+        fonts->resize(w, h);
+    }
+
+    //fprintf(stderr, "screen_buffer size: %d\n", sizeof(screen_buffer));
+    printf("screen_buffer size: %d %d\n", w, h);
+
+    if (screen_buffer) {
+        delete[] screen_buffer;
+        screen_buffer = NULL;
+    }
+
+    screen_buffer = new unsigned char[4*win_width*win_height];
+    assert(screen_buffer != NULL);
+
+    //delete the current render buffer resources
+    glDeleteTextures(1, &final_color_tex);
+    glDeleteFramebuffersEXT(1, &final_fbo);
+
+    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
+    glDeleteRenderbuffersEXT(1, &final_depth_rb);
+
+    //change the camera setting
+    cam->set_screen_size(0, 0, win_width, win_height);
+    plane_render->set_screen_size(win_width, win_height);
+
+    //Reinitialize final fbo for final display
     glGenFramebuffersEXT(1, &final_fbo);
     glGenTextures(1, &final_color_tex);
@@ -596,4 +690,5 @@
 
     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
+    CheckFramebuffer("final_fbo");
 
     //initialize final color texture
@@ -612,4 +707,8 @@
                               GL_TEXTURE_2D, final_color_tex, 0);
 
+    CheckGL("glFramebufferText2DEXT");
+    CheckFramebuffer("final_color_tex");
+    CHECK_FRAMEBUFFER_STATUS();
+
     // initialize final depth renderbuffer
     glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
@@ -621,77 +720,10 @@
 
     // Check framebuffer completeness at the end of initialization.
+    CheckGL("glFramebufferRenderbufferEXT");
+    CheckFramebuffer("final_depth_rb");
     CHECK_FRAMEBUFFER_STATUS();
-
-    //assert(glGetError()==0);
-}
-
-
-//resize the offscreen buffer 
-void 
-NanoVis::resize_offscreen_buffer(int w, int h)
-{
-    win_width = w;
-    win_height = h;
-
-    if (fonts) {
-        fonts->resize(w, h);
-    }
-
-    //fprintf(stderr, "screen_buffer size: %d\n", sizeof(screen_buffer));
-    printf("screen_buffer size: %d %d\n", w, h);
-
-    if (screen_buffer) {
-        delete[] screen_buffer;
-        screen_buffer = NULL;
-    }
-
-    screen_buffer = new unsigned char[4*win_width*win_height];
-    assert(screen_buffer != NULL);
-
-    //delete the current render buffer resources
-    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
-    glDeleteTextures(1, &final_color_tex);
-    glDeleteFramebuffersEXT(1, &final_fbo);
-
-    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
-    glDeleteRenderbuffersEXT(1, &final_depth_rb);
-
-    //change the camera setting
-    cam->set_screen_size(0, 0, win_width, win_height);
-    plane_render->set_screen_size(win_width, win_height);
-
-    //Reinitialize final fbo for final display
-    glGenFramebuffersEXT(1, &final_fbo);
-    glGenTextures(1, &final_color_tex);
-    glGenRenderbuffersEXT(1, &final_depth_rb);
-
-    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
-
-    //initialize final color texture
-    glBindTexture(GL_TEXTURE_2D, final_color_tex);
-    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-#ifdef NV40
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, win_width, win_height, 0,
-                 GL_RGB, GL_INT, NULL);
-#else
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0,
-                 GL_RGB, GL_INT, NULL);
-#endif
-    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
-                              GL_COLOR_ATTACHMENT0_EXT,
-                              GL_TEXTURE_2D, final_color_tex, 0);
-
-    // initialize final depth renderbuffer
-    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, final_depth_rb);
-    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
-                             GL_DEPTH_COMPONENT24, win_width, win_height);
-    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
-                                 GL_DEPTH_ATTACHMENT_EXT,
-                                 GL_RENDERBUFFER_EXT, final_depth_rb);
-
-    // Check framebuffer completeness at the end of initialization.
-    CHECK_FRAMEBUFFER_STATUS();
-    //assert(glGetError()==0);
+    if (debug_flag) {
+       fprintf(stderr, "leaving resize_offscreen_buffer(%d, %d)\n", w, h);
+    }
 }
 
@@ -790,5 +822,4 @@
     GLenum err = glewInit();
     if (GLEW_OK != err) {
-        //glew init failed, exit.
         fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
         getchar();
@@ -823,5 +854,7 @@
     grid->setFont(fonts);
 
+#ifdef notdef
     pointset_renderer = new PointSetRenderer();
+#endif
 }
 
@@ -830,4 +863,7 @@
 NanoVis::initGL(void)
 {
+   if (debug_flag) {
+       fprintf(stderr, "in initGL\n");
+   }
    //buffer to store data read from the screen
    if (screen_buffer) {
@@ -879,22 +915,7 @@
    vol_renderer = new VolumeRenderer();
 
-
    // create
    renderContext = new graphics::RenderContext();
    
-#ifdef notdef
-   //I added this to debug : Wei
-   float tmp_data[4*124];
-   memset(tmp_data, 0, 4*4*124);
-   TransferFunction* tmp_tf = new TransferFunction(124, tmp_data);
-   vol_renderer->add_volume(volume[0], tmp_tf);
-   volume[0]->get_cutplane(0)->enabled = false;
-   volume[0]->get_cutplane(1)->enabled = false;
-   volume[0]->get_cutplane(2)->enabled = false;
-
-   //volume[1]->move(Vector3(0.5, 0.6, 0.7));
-   //vol_renderer->add_volume(volume[1], tmp_tf);
-#endif
-
    //create an 2D plane renderer
    plane_render = new PlaneRenderer(g_context, win_width, win_height);
@@ -910,4 +931,7 @@
    NanoVis::init_lic();
 #endif
+   if (debug_flag) {
+       fprintf(stderr, "leaving initGL\n");
+   }
 }
 
@@ -2385,10 +2409,10 @@
     }
     NanoVis::initGL();
+#ifdef EVENTLOG
+    NvInitEventLog();
+#endif
     Tcl_DStringInit(&NanoVis::cmdbuffer);
     NanoVis::interp = initTcl();
 
-#ifdef EVENTLOG
-    NvInitEventLog();
-#endif
     glutMainLoop();
 
