Providing QGraphicsScene using OpenGL in Qt

I am trying to save a QGraphicsScene with OpenGL as an image (png or jpeg), but I do not want the image to depend on the current view (zoom). This is why I do not use grabFrameBuffer, but instead I use render ():

QImage imgToSave(1024,768,QImage::Format_ARGB32_Premultiplied); // fill the image // and define rectbuffer(), the QRect() containing what I want to save QPainter painter(&imgToSave); m_scene = new QGraphicsScene; // fill the Scene m_scene->render(&painter,imgToSave.rect(),rectbuffer()); 

He works. My question is: Does OpenGL use features or not? If not, how to do it?

nb: I use QGLWidget as a viewport for my GraphicsView. And the display using OpenGL works. My concerns are about saving images.

+4
source share
1 answer

I'm going to guess: no. Since for QGraphicsScene for rendering via OpenGL you need to specify the object received in QGLWidget as the scene viewing area - you did not do this, so you almost certainly use a raster engine. Secondly, QPainter uses any paint device that you create it, as a backend, you specified a direct QImage that does not use OpenGL.

If you cannot / will not use QGLWidget through QGraphicsView , then you can display on QGLFramebufferObject . But this brings its complications, namely, you will have to create a hidden context in advance.

+1
source

Source: https://habr.com/ru/post/1398811/


All Articles