How to get a reliable QGLWidget snapshot

In my application, I take QGLWidget snapshots for two purposes:

  • Do not redraw the scene all the time when only the overlay changes, using the cached pixmap instead
  • Allows the user to take screenshots of individual scenes (3D scene).

The first thing I tried is grabFrameBuffer(). It’s natural to use this function as for the first application, what is currently visible in widgets is exactly what I want to cache. PROBLEM: . On some hardware (for example, Intel-compatible Mac OS X graphics with GeForce graphics), the resulting image does not contain the current screen content, but the content before that. So, if the scene is drawn twice, on the screen you will see the second drawing, in the image you will see the first drawing (which should be the contents of the back buffer?).

The second thing I tried is renderToPixmap(). This means use paintGL(), but not use paint(). I have all my stuff in paint(), since I use the Qt coloring functions, and only a small part of the code uses its own GL ( beginNativePainting(), endNativePainting()).

I also tried the regular QWidget snapshot feature (QPixmap :: fromWidget () or whatever it is called), but the GL framebuffer is black there.

Any ideas on how to solve the problem and get a reliable image of the current scene?

+5
source share
4 answers

How to take a reliable shot of QGLWidget

Display current scene in framebuffer, save data from framebuffer to file. Or grab the current backbuffer after glFlush. Everything else may include artifacts or an incomplete scene.

+2

, QGLWidget:: grabFrameBuffer() glReadPixels() OpenGL. (GL_BACK), OpenGL glReadBuffer (GL_FRONT) QGLWidget:: grabFrameBuffer(), .

+2

QGLWidget::grabFrameBuffer(), OpenGL, . Qt , , Qt. , , , .

+1
source

I use paintGL();and glFlush(); before use grabFrameBuffer(). PaintGL helps draw the current frame again before grabbing the frame buffer, which makes an exact copy of what is currently being displayed.

0
source

All Articles