Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Capturing the Headless Server image using QOpenGLFrameBufferObject
Forum Update on Monday, May 27th 2025

Capturing the Headless Server image using QOpenGLFrameBufferObject

Scheduled Pinned Locked Moved Unsolved General and Desktop
framebufferobje
3 Posts 2 Posters 291 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SyamRam
    wrote on last edited by
    #1

    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(

    eyllanescE 1 Reply Last reply
    0
    • S SyamRam

      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(

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @SyamRam please format your code using three tiks: ` before and after code

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SyamRam
        wrote on last edited by
        #3

        "`"

        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");

        "`"

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved