Do offscreen render(openGL) with Qt5

前端 未结 1 1396
轻奢々
轻奢々 2021-01-18 06:25

Using openGL to do some image processing, the first experiment is convert the color image to gray, everything are fine except I don’t want to show the widget.

If I d

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 07:05

    For offscreen rendering, try rendering into a QOpenGLFramebufferObject, which can be converted into a QImage, which in turn can easily be saved to disk.

    For that however, you still need a surface to render onto (as required by QOpenGLContext::makeCurrent()), so your only choice is indeed using a QWindow or a QGLWidget to get such a surface.

    In Qt 5.1, there will be a new class called QOffscreenSurface, which will probably be most suitable for your usecase. You would use QOffscreenSurface to get a surface for your OpenGL context, and then render into a FBO using QOpenGLFramebufferObject, and then call QOpenGLFramebufferObject::toImage() to get access to the pixels.

    0 讨论(0)
提交回复
热议问题