Hey,

I am wondering what is the proper way to implement offscreen "offline" rendering with QGLWidget. By "offline", I mean without displaying any GUI. The "online" mode works well,here is the code of the offscreen render method:

Qt Code:
  1. ///////////////////////////////
  2. // Render the scene into a png
  3. ///////////////////////////////
  4. void GlView::renderOffScreen()
  5. {
  6.  
  7. // We need to have a valid openGL context
  8. makeCurrent();
  9.  
  10. QGLFramebufferObject * fb = new QGLFramebufferObject(8000,1000, GL_TEXTURE_2D);
  11.  
  12. // bind it and let's start drawing on it....
  13. fb->bind();
  14.  
  15. glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
  16.  
  17. // this must be the same size as the FrameBuffer....
  18. glViewport(0, 0, 8000, 1000);
  19.  
  20. glMatrixMode(GL_PROJECTION);
  21. glLoadIdentity();
  22.  
  23. gluOrtho2D(camera->left(),
  24. camera->right(),
  25. camera->bottom(),
  26. camera->top());
  27.  
  28. glMatrixMode(GL_MODELVIEW);
  29. glLoadIdentity();
  30.  
  31. // renderData........
  32. renderData();
  33.  
  34. fb->release();
  35.  
  36. // reset the viewport to its normal self :)
  37. glViewport(0, 0, viewport[2], viewport[3]);
  38.  
  39. // get the fb into a QImage
  40. QImage tempImage = fb->toImage();
  41.  
  42. // Delete the FB
  43. delete fb;
  44.  
  45. // Save the image
  46. if ( !tempImage.save( "hello.png", "PNG") )
  47. return;
  48.  
  49. }
To copy to clipboard, switch view to plain text mode 

To have the "offline" version, I simply deleted the call to show on the main widget...
It works on Linux (even though you clearly the something is created then deleted), but not on win32.... so I wonder if there is a more proper solution to this.....

Thanks