如何获取可靠的QGLWidget快照 [英] How to take reliable QGLWidget snapshot

查看:120
本文介绍了如何获取可靠的QGLWidget快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,为两个目的拍摄QGLWidget内容的快照:

In my application I take snapshots of a QGLWidget's contents for two purposes:

  • 仅当覆盖层发生变化时,不要一直重绘场景,而是使用缓存的像素图
  • 让用户拍摄特定场景(3D场景)的屏幕截图

我尝试的第一件事是grabFrameBuffer().对于第一个应用程序自然使用此功能,当前在小部件中可见的正是我要缓存的内容. 问题:在某些硬件上(例如Intel集成图形,带有GeForce图形的Mac OS X),所获得的图像不包含当前屏幕内容,而是包含之前的内容.因此,如果场景要绘制两次,则在屏幕上您将看到第二张图,在图像中您将看到第一张图(应该是后缓冲区的内容?).

The first thing I tried is grabFrameBuffer(). It is natural to use this function as for the first application, what is currently visible in the widget is exactly what I want to cache. PROBLEM: On some hardware (e.g. Intel integrade graphics, Mac OS X with GeForce graphics), the image obtained does not contain the current screen content, but the content before that. So if the scene would be drawn two times, on the screen you see the second drawing, in the image you see the first drawing (which should be the content of the backbuffer?).

我尝试的第二件事是renderToPixmap().这使用paintGL()而不是paint()进行渲染.我将所有内容都保存在paint()中,因为我使用了Qt的绘画功能,只有一小部分代码使用了本机GL(beginNativePainting()endNativePainting()).

The second thing I tried is renderToPixmap(). This renders using paintGL(), but not using paint(). I have all my stuff in paint(), as I use Qt's painting functionality and only a small piece of the code uses native GL (beginNativePainting(), endNativePainting()).

我还尝试了常规QWidget的快照功能(QPixmap :: fromWidget()或所谓的快照功能),但是GL帧缓冲区是黑色的.

I also tried the regular QWidget's snapshot capability (QPixmap::fromWidget(), or what it is called), but there the GL framebuffer is black.

关于如何解决问题并获得当前绘制场景的可靠描述的任何想法吗?

Any ideas on how to resolve the issue and get a reliable depiction of the currently drawn scene?

推荐答案

如何获取可靠的QGLWidget快照

How to take reliable QGLWidget snapshot

将当前场景渲染到帧缓冲区,将数据从帧缓冲区保存到文件.或在glFlush之后获取当前的后备缓冲区.其他可能包括伪影或不完整的场景.

Render current scene to framebuffer, save data from framebuffer to file. Or grab current backbuffer after glFlush. Anything else might include artifacts or incomplete scene.

这篇关于如何获取可靠的QGLWidget快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆