title: Off screen rendering on a linux virtual machine
body: <p>I'm currently working on a Linux virtual machine (Ubuntu 16-04 LTS) that has no GPU (because the cluster it runs on has no GPU).</p>
  
  <p>I'm using the following simple C++ code to generate a thumbnail for a .PLY 3D model without opening a window and rendering everything off screen:</p>
  
  <pre><code>void produceThumbnail(const char* input, const char* output)
  {
      viz::Mesh mesh = viz::Mesh::load(input);
      viz::WMesh wMesh(mesh);
      viz::Viz3d window("bunny");
      window.showWidget("bunny", wMesh);
      window.setBackgroundColor(viz::Color::azure());
      window.setOffScreenRendering();
      window.spinOnce();
      Mat3b img = window.getScreenshot();
      imwrite(output, img);
  }
  </code></pre>
  
  <p>Using OpenCV 3.1.0 and VTK 6.3.0 everything works fine on Windows but on Linux i get a different behavior.</p>
  
  <p>While debugging it, when <code>spinOnce()</code> is reached a window opens up anyway, even if i called <code>setOffScreenRendering()</code>, and in the console i get this error:</p>
  
  <pre><code>libGL error: No matching fbConfigs or visuals found
  libGL error: failed to load driver: swrast
  </code></pre>
  
  <p>Despite the errors and the strange behavior the thumbnails are correctly produced and saved.</p>
  
  <p>The real problem is that when I try execute this function when an X server is not available (e.g. NOT a remote desktop connection, an SSH console or something similar) i get the following error:</p>
  
  <pre><code>ERROR: In /home/administrator/libs/VTK-6.3.0/Rendering/OpenGL/vtkXOpenGlRenderWindow.cxx, line 1475
  vtkXOpenGLRenderWindow (0x1ae93e0): bad X server connection. DISPLAY=Aborted
  </code></pre>
  
  <p>and the executable crashes (obviously, because there is no X server available... )</p>
  
  <p>Looking online I have found many questions regarding wrong GPU-hardware/GPU-drivers configuration but nothing quite like my own case.</p>
  
  <p>Running <code>glxgears</code> i get this:</p>
  
  <pre><code>libGL: OpenDriver: trying /usr/lib/x86_64-linux-gnu/dri/tls/swrast_dri.so
  libGL: OpenDriver: trying /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
  libGL error: No matching fbConfigs or visuals found
  libGL error: failed to load driver: swrast
  28843 frames in 5.0 seconds = 5766.824 FPS
  28840 frames in 5.0 seconds = 5766.716 FPS
  ...
  </code></pre>
  
  <p>And running <code>glxinfo</code> i get this:</p>
  
  <pre><code>name of display: :10.0
  libGL error: No matching fbConfigs or visuals found
  libGL error: failed to load driver: swrast
  display: :10  screen: 0
  direct rendering: No (If you want to find out why, try setting LIBGL_DEBUG=verbose)
  server glx vendor string: SGI
  server glx version string: 1.2
  server glx extensions:
      GLX_EXT_import_context, GLX_EXT_visual_info, GLX_EXT_visual_rating
  client glx vendor string: Mesa Project and SGI
  client glx version string: 1.4
  client glx extensions:
      GLX_ARB_create_context, GLX_ARB_create_context_profile, 
      GLX_ARB_create_context_robustness, GLX_ARB_fbconfig_float, 
      GLX_ARB_framebuffer_sRGB, GLX_ARB_get_proc_address, GLX_ARB_multisample, 
      GLX_EXT_buffer_age, GLX_EXT_create_context_es2_profile, 
      GLX_EXT_create_context_es_profile, GLX_EXT_fbconfig_packed_float, 
      GLX_EXT_framebuffer_sRGB, GLX_EXT_import_context, 
      GLX_EXT_texture_from_pixmap, GLX_EXT_visual_info, GLX_EXT_visual_rating, 
      GLX_INTEL_swap_event, GLX_MESA_copy_sub_buffer, 
      GLX_MESA_multithread_makecurrent, GLX_MESA_query_renderer, 
      GLX_MESA_swap_control, GLX_OML_swap_method, GLX_OML_sync_control, 
      GLX_SGIS_multisample, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer, 
      GLX_SGIX_visual_select_group, GLX_SGI_make_current_read, 
      GLX_SGI_swap_control, GLX_SGI_video_sync
  GLX version: 1.2
  GLX extensions:
      GLX_ARB_get_proc_address, GLX_EXT_import_context, GLX_EXT_visual_info, 
      GLX_EXT_visual_rating, GLX_MESA_multithread_makecurrent
  OpenGL vendor string: Mesa project: www.mesa3d.org
  OpenGL renderer string: Mesa GLX Indirect
  OpenGL version string: 1.3 Mesa 4.0.4
  OpenGL extensions:
      GL_ARB_imaging, GL_ARB_multitexture, GL_ARB_texture_border_clamp, 
      GL_ARB_texture_cube_map, GL_ARB_texture_env_add, 
      GL_ARB_texture_env_combine, GL_ARB_texture_env_dot3, 
      GL_ARB_transpose_matrix, GL_EXT_abgr, GL_EXT_blend_color, 
      GL_EXT_blend_minmax, GL_EXT_blend_subtract, GL_EXT_draw_range_elements, 
      GL_EXT_multi_draw_arrays, GL_EXT_texture_env_add, 
      GL_EXT_texture_env_combine, GL_EXT_texture_env_dot3, 
      GL_EXT_texture_lod_bias, GL_SGIS_texture_border_clamp, 
      GL_SUN_multi_draw_arrays
  </code></pre>
  
  <p>I get that there must be something wrong with my driver configuration but i'm not really into these things (Linux configuration + 3D graphics + software rendering + etc) so i don't know what can i do to fix this.</p>
  
  <p>Any suggestion about how can i solve this issue? (Or about doing the same thing in different way)</p>