[Qt-interest] QGLWidget and off-screen rendering.

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Nov 4 10:18:38 CET 2009


John Clayton wrote on Wednesday, November 04, 2009 8:42 AM:

> Hi All,
> 
> I'm trying to render the contents of a qgraphicsview offscreen.  To
> do this I've got a QGLWidget and overriden its paintGL() method. 

Hmmm, not sure if this is the way to go. Actually for pure off-screen rendering one would use:

  - http://doc.trolltech.com/4.5/qglframebufferobject.html ("Pbuffers" extension) or
  - http://doc.trolltech.com/4.5/qglpixelbuffer.html

Did you consider these?

>From the docs of QGLFramebufferObject:

"OpenGL framebuffer objects and pbuffers (see QGLPixelBuffer) can both be used to render to offscreen surfaces, but there are a number of advantages with using framebuffer objects instead of pbuffers:

   1. A framebuffer object does not require a separate rendering context, so no context switching will occur when switching rendering targets. There is an overhead involved in switching targets, but in general it is cheaper than a context switch to a pbuffer.
   2. Rendering to dynamic textures (i.e. render-to-texture functionality) works on all platforms. No need to do explicit copy calls from a render buffer into a texture, as was necessary on systems that did not support the render_texture extension.
   3. It is possible to attach several rendering buffers (or texture objects) to the same framebuffer object, and render to all of them without doing a context switch.
   4. The OpenGL framebuffer extension is a pure GL extension with no system dependant WGL, CGL, or GLX parts. This makes using framebuffer objects more portable.
"

I remember I had difficulties setting up a valid GL context ("It is important to have a current GL context when creating a QGLFramebufferObject, otherwise initialization will fail.") for a QGLFramebuffer. I got a hint creating a "dummy" (invisible) QGLWidget and use its QGLContext, but I did not try that. But if you have a QGLWidget anyway, you might go for QGLFrameBuffer, which has several advantages over "pbuffers" (QGLPixelBuffer), see above. In the end I used QGLPixelBuffer, and I was able to successfully initialise it without creating any other QGLWidget (given that your hardware supports "pbuffers" GL extension, which I believe most recent graphic cards do nowadays).



Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list