diff -rcN vtkOffScreen/Makefile vtkOffScreen-OSMesa/Makefile
*** vtkOffScreen/Makefile	Wed Nov 22 23:36:27 2000
--- vtkOffScreen-OSMesa/Makefile	Thu Oct 11 14:26:38 2001
***************
*** 26,51 ****
  # For Linux ##########################################
  CC = gcc
  CXX = g++
! CFLAGS = -g -O -DUSE_PIXMAP -DOFFSCREEN
! XLIBS =  -L/usr/X11R6/lib  -lXt -lXext -lX11 -lpthread -ldl -lm
  XGLLIBS =  -lMesaGL $(XLIBS)
  
  # Paths to vtk installation ######################
! VTKHOME = /home/jshalf/Develop/vtk31.orig
  # VTKHOME = /raid/people/jshalf/Develop/vtk2.3
! VTKINCD = $(VTKHOME)/include
  
  # Generic stuff ######################################
  VTKINC = -I$(VTKINCD) -I$(VTKINCD)/common -I$(VTKINCD)/contrib -I$(VTKINCD)/graphics -I$(VTKINCD)/imaging 
! VTKLIB = -L$(VTKHOME)/lib -lVTKPatented -lVTKGraphics -lVTKImaging -lVTKCommon
  
! all: vtkSphere_ex
  
  glpixmap_ex: glpixmap_ex.o Makefile
  	$(CXX) $(CFLAGS) -o glpixmap_ex glpixmap_ex.o $(XGLLIBS)
  
  glpixmap_ex.o: glpixmap_ex.cc Makefile 
  	$(CXX) $(CFLAGS) -c glpixmap_ex.cc
  
  vtkSphere_ex: vtkSphere_ex.o vtkOpenGLOffscreenRenderWindow.o vtkOpenGLOffscreenTexture.o Makefile
  	$(CXX) $(CFLAGS) -o vtkSphere_ex vtkSphere_ex.o \
--- 26,65 ----
  # For Linux ##########################################
  CC = gcc
  CXX = g++
! # CFLAGS = -g -O -DUSE_PIXMAP -DOFFSCREEN
! CFLAGS = -g -O -DUSE_OSMESA -DOFFSCREEN -I/usr/X11R6/include
! # XLIBS =  -L/usr/X11R6/lib  -lXt -lXext -lX11 -lpthread -ldl -lm
! XLIBS =  -L/usr/X11R6/lib  -lXt -lXext -lX11 -lpthread -lm
  XGLLIBS =  -lMesaGL $(XLIBS)
  
  # Paths to vtk installation ######################
! # VTKHOME = /home/jshalf/Develop/vtk31.orig
  # VTKHOME = /raid/people/jshalf/Develop/vtk2.3
! # VTKINCD = $(VTKHOME)/include
! VTKHOME = ../vtk3.2
! VTKINCD = $(VTKHOME)
  
  # Generic stuff ######################################
  VTKINC = -I$(VTKINCD) -I$(VTKINCD)/common -I$(VTKINCD)/contrib -I$(VTKINCD)/graphics -I$(VTKINCD)/imaging 
! # VTKLIB = -L$(VTKHOME)/lib -lVTKPatented -lVTKGraphics -lVTKImaging -lVTKCommon
! VTKLIB = -L/usr/local/lib -lVTKGraphics -lVTKImaging -lVTKCommon
  
! #all: vtkSphere_ex
! all: vtkText_ex
  
  glpixmap_ex: glpixmap_ex.o Makefile
  	$(CXX) $(CFLAGS) -o glpixmap_ex glpixmap_ex.o $(XGLLIBS)
  
  glpixmap_ex.o: glpixmap_ex.cc Makefile 
  	$(CXX) $(CFLAGS) -c glpixmap_ex.cc
+ 
+ vtkText_ex: vtkText_ex.o vtkOpenGLOffscreenRenderWindow.o vtkOpenGLOffscreenTexture.o Makefile
+ 	$(CXX) $(CFLAGS) -o vtkText_ex vtkText_ex.o \
+ 		vtkOpenGLOffscreenRenderWindow.o \
+ 		vtkOpenGLOffscreenTexture.o \
+ 		$(VTKLIB) $(XGLLIBS)
+ vtkText_ex.o: vtkText_ex.cc vtkOpenGLOffscreenRenderWindow.h Makefile
+ 	$(CXX) $(CFLAGS) $(VTKINC) -c vtkText_ex.cc
  
  vtkSphere_ex: vtkSphere_ex.o vtkOpenGLOffscreenRenderWindow.o vtkOpenGLOffscreenTexture.o Makefile
  	$(CXX) $(CFLAGS) -o vtkSphere_ex vtkSphere_ex.o \
diff -rcN vtkOffScreen/vtkOpenGLOffscreenRenderWindow.cxx vtkOffScreen-OSMesa/vtkOpenGLOffscreenRenderWindow.cxx
*** vtkOffScreen/vtkOpenGLOffscreenRenderWindow.cxx	Wed Nov 22 23:36:27 2000
--- vtkOffScreen-OSMesa/vtkOpenGLOffscreenRenderWindow.cxx	Thu Oct 11 14:34:17 2001
***************
*** 78,83 ****
--- 78,88 ----
  #ifdef USE_DMEDIA
  #include <dmedia/cl.h>
  #endif
+ #ifdef USE_OSMESA
+ #include <GL/osmesa.h>
+ OSMesaContext osmesa_ctx = 0;
+ void * osmesa_buffer = (void *) NULL;
+ #endif // USE_OSMESA
  
  #define MAX_LIGHTS 8
  
***************
*** 197,202 ****
--- 202,251 ----
  int vtkOpenGLOffscreenRenderWindow::WriteJPEG(char *filename,float compressionRatio){ puts("Unsupported (enable with #define USE_DMEDIA or compile with -DUSE_DMEDIA if you are on an SGI system)");}
  #endif
  //----------------------------------------------------------------
+ static void
+ write_ppm(const char *filename, void *buffer, int width, int height)
+ {
+    const int binary = 1;
+    FILE *f = fopen( filename, "w" );
+    if (f) {
+       int i, x, y;
+       const GLubyte *ptr = (GLubyte *) buffer;
+       if (binary) {
+ 	fprintf(f,"P6\n");
+ 	fprintf(f,"# ppm-file created by osdemo.c\n");
+ 	fprintf(f,"%i %i\n", width,height);
+ 	fprintf(f,"255\n");
+ 	fclose(f);
+ 	f = fopen( filename, "ab" );  /* reopen in binary append mode */
+ 	for (y=height-1; y>=0; y--) {
+ 	  for (x=0; x<width; x++) {
+ 	    i = (y*width + x) * 4;
+ 	    fputc(ptr[i], f);   /* write red */
+ 	    fputc(ptr[i+1], f); /* write green */
+ 	    fputc(ptr[i+2], f); /* write blue */
+ 	  }
+ 	}
+       }
+       else {
+ 	/*ASCII*/
+ 	int counter = 0;
+ 	fprintf(f,"P3\n");
+ 	fprintf(f,"# ascii ppm file created by osdemo.c\n");
+ 	fprintf(f,"%i %i\n", width, height);
+ 	fprintf(f,"255\n");
+ 	for (y=height-1; y>=0; y--) {
+ 	  for (x=0; x<width; x++) {
+ 	    i = (y*width + x) * 4;
+ 	    fprintf(f, "%3d %3d %3d ", ptr[i], ptr[i+1], ptr[i+2]);
+ 	    counter++;
+ 	    if (counter % 5 == 0)
+ 	      fprintf(f, "\n");
+ 	  }
+ 	}
+       }
+       fclose(f);
+    }
+ }
  void vtkOpenGLOffscreenRenderWindow::WriteImage(char *filename)
  {
    //XImage *img = this->GetImage(); 
***************
*** 204,209 ****
--- 253,265 ----
    int width = ((this->Size[0] > 0) ? this->Size[0] : 300);
    int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
    offDebugMacro(<< "\tSize is " << width << ':' << height << "\n" ); 
+ #ifdef USE_OSMESA
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+   glFlush ();
+   /* write PPM file */
+   write_ppm (filename, osmesa_buffer, width, height);
+ #else // !USE_OSMESA
    if(this->ContextId && this->DisplayId && this->WindowId){
      glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId); 
      glFlush();
***************
*** 236,241 ****
--- 292,298 ----
    XDestroyImage(img);
  #endif // USE_GLXPPM
  #endif // !USE_PBUFFER
+ #endif // !USE_OSMESA
  }
  
  //----------------------------------------------------------------
***************
*** 459,469 ****
--- 516,530 ----
  // Constructor
  vtkOpenGLOffscreenRenderWindow::vtkOpenGLOffscreenRenderWindow()
  {
+ #ifdef USE_OSMESA
+   cout << "using OSMesa..." << endl;
+ #else // !USE_OSMESA
  #ifdef USE_PBUFFER
    cout << "using PBuffers..." << endl;
  #else
    cout << "NOT using PBuffers..." << endl;
  #endif
+ #endif // !USE_OSMESA
  
    vtkDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::vtkOpenGLOffscreenRenderWindow\n");
    this->framebuffer = 0;
***************
*** 487,492 ****
--- 548,559 ----
  vtkOpenGLOffscreenRenderWindow::~vtkOpenGLOffscreenRenderWindow()
  {
    vtkDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::~vtkOpenGLOffscreenRenderWindow\n");
+ #ifdef USE_OSMESA
+   if (!osmesa_ctx)
+     {
+       this->Destroy();
+     }
+ #else
    /* first delete all the old lights */
    // make sure we have been initialized 
    if(this->framebuffer) delete [] this->framebuffer;
***************
*** 506,516 ****
--- 573,594 ----
       glXDestroyGLXPbufferSGIX(this->DisplayId, this->WindowId);
      */
    }
+ #endif // USE_OSMESA
  }
  
  //----------------------------------------------------------------
  void vtkOpenGLOffscreenRenderWindow::Destroy()
  {
+ #ifdef USE_OSMESA
+   if (!osmesa_ctx)
+     {
+       OSMesaDestroyContext (osmesa_ctx);
+       osmesa_ctx = 0;
+       free (osmesa_buffer);
+       osmesa_buffer = (void *) NULL;
+     }
+ //#else // USE_OSMESA - if you don't use TextMapper, you can skip the below
+ #endif // USE_OSMESA -- TextMapper uses X window ...
    if (this->ContextId) {
      glXDestroyContext( this->DisplayId, this->ContextId);
  #ifdef USE_PBUFFER
***************
*** 522,527 ****
--- 600,606 ----
  #endif
      this->WindowId=0; this->ContextId=0;
    }
+ //#endif // USE_OSMESA - if you don't use TextMapper, you can skip the above
  }
  
  //----------------------------------------------------------------
***************
*** 533,547 ****
--- 612,640 ----
    vtkDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::Start\n");
  
    // if the renderer has not been initialized, do so now
+ #ifdef USE_OSMESA
+   if (!osmesa_ctx)
+     {
+       this->Initialize();
+     }
+ #else
    if (!this->ContextId)
      {
        this->Initialize();
      }
+ #endif // USE_OSMESA
  #ifdef USE_GRABFRAMEBUFFER
    GrabFramebuffer(); // for PBUFFERS
  #endif
    // set the current window 
+ #ifdef USE_OSMESA
+   int width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+ #else
    glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);
+ #endif // USE_OSMESA
  }
  
  //----------------------------------------------------------------
***************
*** 675,680 ****
--- 768,793 ----
    int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
    this->Size[0]=width;
    this->Size[1]=height;
+ #ifdef USE_OSMESA
+   osmesa_ctx = OSMesaCreateContext (GL_RGBA, NULL);
+   osmesa_buffer = malloc (width * height * 4);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+   vtkDebugMacro(<< " OSMesa - glMatrixMode ModelView\n");
+   glMatrixMode( GL_MODELVIEW );
+   vtkDebugMacro(<< " OSMesa - zbuffer enabled\n");
+   glDepthFunc( GL_LEQUAL );
+   glEnable( GL_DEPTH_TEST );
+   vtkDebugMacro(<< " OSMesa - texture stuff\n");
+   glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+   // initialize blending for transparency
+   vtkDebugMacro(<< " OSMesa - blend func stuff\n");
+   glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+   glEnable(GL_BLEND);
+   glEnable( GL_NORMALIZE );
+   glAlphaFunc(GL_GREATER,0);
+ //#else // USE_OSMESA - if you don't use TextMapper, you can skip the below
+ #endif // !USE_OSMESA -- TextMapper uses X window ...
    // this->SetSize(width,height);
    // get the default display connection 
    if (!this->DisplayId) {
***************
*** 702,718 ****
    this->visualdepth=v->depth; /* pixel layout??? */
    /* printf("v->depth=%u\n",v->depth); */
    this->ContextId = glXCreateContext(this->DisplayId,v,0,GL_FALSE);
!   this->WindowId = glXCreateGLXPixmap(this->DisplayId,v,this->pixmap); /*  make gl understand it as a window */
    if (v){
      XFree(v);
    }
    glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);
    vtkDebugMacro(<< " glMatrixMode ModelView\n");
    glMatrixMode( GL_MODELVIEW );
    vtkDebugMacro(<< " zbuffer enabled\n");
    glDepthFunc( GL_LEQUAL );
    glEnable( GL_DEPTH_TEST );
!   vtkDebugMacro(" texture stuff\n");
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    // initialize blending for transparency
    vtkDebugMacro(<< " blend func stuff\n");
--- 815,836 ----
    this->visualdepth=v->depth; /* pixel layout??? */
    /* printf("v->depth=%u\n",v->depth); */
    this->ContextId = glXCreateContext(this->DisplayId,v,0,GL_FALSE);
!   /** glXCreateGLXPixmap() works on FreeBSD, but not work on Linux 2.2.17 **/
!   //this->WindowId = glXCreateGLXPixmap(this->DisplayId,v,this->pixmap); /*  make gl understand it as a window */
!   XWindowAttributes attr;
!   XGetWindowAttributes(this->DisplayId, RootWindow(this->DisplayId,v->screen), &attr );
!   this->WindowId = glXCreateGLXPixmapMESA(this->DisplayId,v,this->pixmap, attr.colormap); /*  make gl understand it as a window */
    if (v){
      XFree(v);
    }
    glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);
+ //#endif // USE_OSMESA - if you don't use TextMapper, you can skip the above
    vtkDebugMacro(<< " glMatrixMode ModelView\n");
    glMatrixMode( GL_MODELVIEW );
    vtkDebugMacro(<< " zbuffer enabled\n");
    glDepthFunc( GL_LEQUAL );
    glEnable( GL_DEPTH_TEST );
!   vtkDebugMacro(<< " texture stuff\n");
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    // initialize blending for transparency
    vtkDebugMacro(<< " blend func stuff\n");
***************
*** 720,735 ****
    glEnable(GL_BLEND);
    glEnable( GL_NORMALIZE );
    glAlphaFunc(GL_GREATER,0);
! #endif
    this->Mapped = 0; // if its mapped, then it trys windowgetattributes which fails!
    this->SwapBuffers = 0;
    this->DoubleBuffer = 0;
  #ifdef USE_GRABFRAMEBUFFER
    ReleaseFramebuffer();
  #endif
  }
  
  void vtkOpenGLOffscreenRenderWindow::GrabFramebuffer(){
    // make sure we haven't already done this
    if(this->DisplayId && this->WindowId && this->ContextId) return;
  #ifdef USE_PBUFFER  
--- 838,858 ----
    glEnable(GL_BLEND);
    glEnable( GL_NORMALIZE );
    glAlphaFunc(GL_GREATER,0);
! #endif // !USE_PBUFFER
    this->Mapped = 0; // if its mapped, then it trys windowgetattributes which fails!
    this->SwapBuffers = 0;
    this->DoubleBuffer = 0;
  #ifdef USE_GRABFRAMEBUFFER
    ReleaseFramebuffer();
  #endif
+ #ifdef USE_OSMESA
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+ #endif // USE_OSMESA
  }
  
  void vtkOpenGLOffscreenRenderWindow::GrabFramebuffer(){
+   vtkDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::GrabFramebuffer\n");
    // make sure we haven't already done this
    if(this->DisplayId && this->WindowId && this->ContextId) return;
  #ifdef USE_PBUFFER  
***************
*** 815,820 ****
--- 938,949 ----
  		  GLsizei width, GLsizei height,
  		  GLenum format, GLenum type,
  		  GLvoid *pixels ){
+  vtkDebugMacro(<< " vtkOpenGLOffscreenRenderWindow::fbReadPixels\n");  
+ #ifdef USE_OSMESA
+   if (osmesa_ctx) {
+     glDrawPixels(width,height,format,type,pixels);
+   }
+ #else // !USE_OSMESA
    if(this->ContextId && this->WindowId){
      //puts("using glReadPixels");
      if(format==GL_RGB) 
***************
*** 947,958 ****
--- 1076,1094 ----
        break;
      }
    }
+ #endif // !USE_OSMESA
  }
  void vtkOpenGLOffscreenRenderWindow::fbDrawPixels(
  		  GLsizei width, GLsizei height,
  		  GLenum format, GLenum type,
  		  GLvoid *pixels ){
    int x=0,y=0;
+  vtkDebugMacro(<< " vtkOpenGLOffscreenRenderWindow::fbDrawPixels\n");  
+ #ifdef USE_OSMESA
+   if (osmesa_ctx) {
+     glDrawPixels(width,height,format,type,pixels);
+   }
+ #else // !USE_OSMESA
    if(this->ContextId && this->WindowId){
      glDrawPixels(width,height,format,type,pixels);
    }
***************
*** 1008,1013 ****
--- 1144,1150 ----
        break;
      }
    }
+ #endif // !USE_OSMESA
  }
  //----------------------------------------------------------------
  // Description:
***************
*** 1110,1116 ****
  }
  
  int *vtkOpenGLOffscreenRenderWindow::GetSize(){
!   offDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::GetSize() " << Size[0] << ":" << Size[1] << "\n");
    return this->Size;
  }
  
--- 1247,1253 ----
  }
  
  int *vtkOpenGLOffscreenRenderWindow::GetSize(){
!   //offDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::GetSize() " << Size[0] << ":" << Size[1] << "\n");
    return this->Size;
  }
  
***************
*** 1168,1173 ****
--- 1305,1317 ----
    unsigned char   *p_data = NULL;
  
    // set the current window 
+ #ifdef USE_OSMESA
+   int width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+   glFlush ();
+ #else // !USE_OSMESA
    if(this->ContextId && this->WindowId && this->DisplayId){
      glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId); 
      glReadBuffer(GL_FRONT);
***************
*** 1178,1183 ****
--- 1322,1328 ----
        glReadBuffer(GL_BACK);
      */
    }
+ #endif // !USE_OSMESA
    
    data = new unsigned char[(abs(x2 - x1) + 1)*(abs(y2 - y1) + 1)*3];
  
***************
*** 1241,1246 ****
--- 1386,1399 ----
    int     xloop,yloop;
    unsigned char   *buffer;
    unsigned char   *p_data = NULL;
+ 
+ #ifdef USE_OSMESA
+   int width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+   glFlush ();
+ #else // !USE_OSMESA
    GrabFramebuffer();
    // set the current window 
    if(this->DisplayId && this->WindowId && this->ContextId){
***************
*** 1254,1259 ****
--- 1407,1413 ----
  	glDrawBuffer(GL_BACK);
      */
    }
+ #endif // !USE_OSMESA
  
    buffer = new unsigned char [4*(abs(x2 - x1)+1)];
  
***************
*** 1309,1315 ****
--- 1463,1471 ----
      }
    
    delete [] buffer;
+ #ifndef USE_OSMESA
    ReleaseFramebuffer();
+ #endif // !USE_OSMESA
  }
  
  float *vtkOpenGLOffscreenRenderWindow::GetRGBAPixelData(int x1, int y1, int x2, int y2, int front)
***************
*** 1321,1331 ****
--- 1477,1496 ----
    int     x_low, x_hi;
    int     width, height;
    float   *data = NULL;
+ 
+ #ifdef USE_OSMESA
+   width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+   glFlush ();
+ #else // !USE_OSMESA
    // set the current window 
    if(this->ContextId && this->WindowId && this->DisplayId){
      glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);  
      glReadBuffer(GL_FRONT);// No Front vs. Back buffers for offscreen!
    }
+ #endif // !USE_OSMESA
    if (y1 < y2)
      {
        y_low = y1; 
***************
*** 1368,1379 ****
--- 1533,1552 ----
    int     y_low, y_hi;
    int     x_low, x_hi;
    int     width, height;
+ #ifdef USE_OSMESA
+   width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+   glFlush ();
+ #else // !USE_OSMESA
    // set the current window 
    if(this->ContextId && this->WindowId && this->DisplayId){
      glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);
      glDrawBuffer(GL_FRONT); // should always be front-buffer (no backbuffer offscreen)
      // no point to having a backbuffer offscreen
    }
+ #endif // !USE_OSMESA
  
    if (y1 < y2)
      {
***************
*** 1433,1441 ****
--- 1606,1621 ----
    int             x_low, x_hi;
    int             width, height;
    float           *z_data = NULL;
+ #ifdef USE_OSMESA
+   width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+ #else // !USE_OSMESA
    // set the current window 
    if(this->ContextId)
      this->MakeCurrent();
+ #endif // !USE_OSMESA
    
    if (y1 < y2)
      {
***************
*** 1482,1489 ****
--- 1662,1676 ----
    int             x_low, x_hi;
    int             width, height;
  
+ #ifdef USE_OSMESA
+   width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+   height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+   OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 		     GL_UNSIGNED_BYTE, width, height);
+ #else // !USE_OSMESA
    // set the current window 
    this->MakeCurrent();
+ #endif // !USE_OSMESA
  
    if (y1 < y2)
      {
***************
*** 1532,1539 ****
--- 1719,1736 ----
    vtkDebugMacro(<< "vtkOpenGLOffscreenRenderWindow::MakeCurrent\n");
  
    // set the current window 
+ #ifdef USE_OSMESA
+   if (osmesa_ctx && osmesa_buffer)
+     {
+       int width = ((this->Size[0] > 0) ? this->Size[0] : 300);
+       int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
+       OSMesaMakeCurrent (osmesa_ctx, osmesa_buffer,
+ 			 GL_UNSIGNED_BYTE, width, height);
+     }
+ #else
    if(this->ContextId && this->WindowId && this->DisplayId)
    glXMakeCurrent(this->DisplayId,this->WindowId,this->ContextId);
+ #endif // USE_OSMESA
  }
  
  // return the current framebuffer as a JPG image
diff -rcN vtkOffScreen/vtkText_ex.cc vtkOffScreen-OSMesa/vtkText_ex.cc
*** vtkOffScreen/vtkText_ex.cc	Thu Jan  1 01:00:00 1970
--- vtkOffScreen-OSMesa/vtkText_ex.cc	Thu Oct 11 14:11:55 2001
***************
*** 0 ****
--- 1,123 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include "vtkOpenGLOffscreenRenderWindow.h"
+ #include <vtkRenderer.h>
+ #include <vtkSphereSource.h>
+ #include <vtkConeSource.h>
+ #include <vtkTextMapper.h>
+ //#include <vtkXMesaTextMapper.h>
+ #include <vtkScaledTextActor.h>
+ #include <vtkActor.h>
+ #include <vtkPolyDataMapper.h>
+ //#include <vtk.h>
+ /*
+ #ifdef OFFSCREEN 
+ #undef OFFSCREEN
+ #endif
+ */
+ 
+ /********************************************************************
+ Draw a vtkSphere using offscreen rendering and write to a ppm file
+ called "sphere.ppm".
+ *********************************************************************/
+ main (){
+ #ifdef OFFSCREEN
+   vtkOpenGLOffscreenRenderWindow *renWin= vtkOpenGLOffscreenRenderWindow::New(); 
+   renWin->SetSize(512,512);
+ #else
+   vtkRenderWindow *renWin = vtkRenderWindow::New();
+ #endif
+   // renWin->DebugOn();
+   vtkRenderer *ren1;
+   vtkConeSource *cone;
+   vtkPolyDataMapper *map;
+   vtkActor *aCone;
+ 
+   vtkConeSource *cone2;
+   vtkPolyDataMapper *map2;
+   vtkActor *aCone2;
+ 
+   vtkSphereSource *sphere;
+   vtkPolyDataMapper *sMap;
+   vtkActor *aSphere;
+ 
+   vtkTextMapper * textMapper;
+   //vtkXMesaTextMapper * textMapper;
+   vtkScaledTextActor * textActor;
+ 
+   // You must render everything in immediate mode when
+   // you do offscreen rendering in order to get consistent
+   // results.
+   vtkMapper::GlobalImmediateModeRenderingOn();
+   // create a window, renderer and interactor
+   ren1 = vtkRenderer::New();
+   // ren1->DebugOn();
+   renWin->AddRenderer(ren1);
+ 
+ 
+   // create cone geometry
+   cone = vtkConeSource::New();
+   cone->SetAngle(45);
+   // map to graphics library
+   map = vtkPolyDataMapper::New();
+   map->SetInput(cone->GetOutput());
+   // actor coordinates geometry, properties, transformation
+   aCone = vtkActor::New();
+   aCone->SetMapper(map);
+   aCone->GetProperty()->SetColor(0,0,1); // cone color blue
+   aCone->GetProperty()->SetOpacity(0.5);
+   ren1->AddActor(aCone);
+ 
+   cone2 = vtkConeSource::New();
+   cone2->SetAngle(30);
+   map2 = vtkPolyDataMapper::New();
+   map2->SetInput(cone2->GetOutput());
+   aCone2 = vtkActor::New();
+   aCone2->SetMapper(map2);
+   aCone2->GetProperty()->SetColor(1,0,0);
+   ren1->AddActor(aCone2);
+ 
+   sphere = vtkSphereSource::New();
+   sphere->SetRadius(0.5);
+   sphere->SetThetaResolution(18);
+   sphere->SetPhiResolution(18);
+   sMap = vtkPolyDataMapper::New();
+   sMap->SetInput(sphere->GetOutput());
+   aSphere = vtkActor::New();
+   aSphere->SetMapper(sMap);
+   aSphere->GetProperty()->SetColor(0,1,0);
+   aSphere->GetProperty()->SetOpacity(0.5);
+   ren1->AddActor(aSphere);
+ 
+   textMapper = vtkTextMapper::New ();
+   //textMapper = vtkXMesaTextMapper::New ();
+   textMapper->SetInput ("test TEST");
+   textMapper->SetFontSize (18);
+   textMapper->SetFontFamilyToArial ();
+   textMapper->SetJustificationToCentered ();
+   textMapper->BoldOn ();
+   textMapper->ItalicOn ();
+   textMapper->ShadowOn ();
+   textActor = vtkScaledTextActor::New ();
+   textActor->SetMapper (textMapper);
+   textActor->GetProperty()->SetColor (0,0,1);
+   textActor->SetPosition (5.0, 5.0);
+   ren1->AddActor(textActor);
+ 
+   ren1->SetBackground(1,1,1); // Background color white
+   ren1->GetActiveCamera()->Roll(90);
+   // Render an image; since no lights/cameras specified, created automatically
+   renWin->Render();
+   puts("WriteImage");
+   // sleep(6);
+ #ifndef OFFSCREEN
+   sleep(5);
+ #else
+   renWin->WriteImage("vtkText_ex.ppm");
+ #ifdef USE_DMEDIA
+   renWin->WriteJPEG("vtkText_ex.jpeg");
+ #endif
+ #endif
+   puts("done");
+ }
