Capturing the Headless Server image using QOpenGLFrameBufferObject
-
Hi,
My application having multiple QGLWIdgets plotting in MainWindow. When am trying to capture Single QOPenFLWIdget image using
m_fbo->toImage().convertToFormat(QImage::Format_RGB32);
fb.save(ImageName, "PNG");
but not able to capture all displayed QOPenGLWidgets which are plotting in mainwindow.
My application have 10 OpenGLWidgets Plotting in sametime based on timestamp.Here am using One QOpenGLFrameBufferObject in mainwindow to capture multiple QOpenGLWidgets.
mainwidnow.cpp
QSurfaceFormat surfaceFormat;
surfaceFormat.setMajorVersion(4);
surfaceFormat.setMinorVersion(3);QOpenGLContext openGLContext;
openGLContext.setFormat(surfaceFormat);// QOpenGLContext::currentContext()->functions()->glFlush();
openGLContext.create();
if(!openGLContext.isValid()) return -1;QOffscreenSurface surface;
surface.setFormat(surfaceFormat);
surface.create();
if(!surface.isValid()) return -2;openGLContext.makeCurrent(&surface);
QOpenGLFunctions *f = openGLContext.currentContext()->functions(); f->initializeOpenGLFunctions();
// openGLContext.currentContext()->functions()->glFlush();
f->glFlush();// QOpenGLFunctions_4_3_Core f;
// if(!f->initializeOpenGLFunctions()) return -3;qDebug() << QString::fromLatin1((const char*)f->glGetString(GL_VERSION));
QSize vpSize = QSize(100, 200);
qDebug("Hi");
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
QOpenGLFramebufferObject fbo(vpSize, fboFormat);fboFormat.setTextureTarget(GL_TEXTURE_2D);
fbo.bind();
RenderAllOpenGLWidgets();
QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32);
fb.save("image_file.png", "PNG");fbo.release();
for(
-
"`"
QSurfaceFormat surfaceFormat;
surfaceFormat.setMajorVersion(4);
surfaceFormat.setMinorVersion(3);QOpenGLContext openGLContext;
openGLContext.setFormat(surfaceFormat);
openGLContext.create();QOffscreenSurface surface;
surface.setFormat(surfaceFormat);
surface.create();openGLContext.makeCurrent(&surface);
QOpenGLFunctions *f = openGLContext.currentContext()->functions();
f->initializeOpenGLFunctions();
f->glFlush();QSize vpSize = QSize(m_ScreenWidth, m_ScreenHeight);
qDebug("Hi");
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);m_fbo = new QOpenGLFramebufferObject (vpSize, fboFormat);
fboFormat.setTextureTarget(GL_TEXTURE_2D);RenderAllOPenGLWidgets(); // reendering all widgets based on timestamp.
this->update();
QCoreApplication::processEvents();
QThread::usleep(1000);m_fbo->release();
QString ImageName = QString::number(FBOCaptureTime) + QString(".png");;
QImage fb = m_fbo->toImage().convertToFormat(QImage::Format_RGB32);
fb.save(ImageName, "PNG");"`"