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. How to grab the Framebuffer in QOpenGLWidget class.
Forum Updated to NodeBB v4.3 + New Features

How to grab the Framebuffer in QOpenGLWidget class.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 670 Views 1 Watching
  • 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.
  • B Offline
    B Offline
    BPrasad
    wrote on last edited by
    #1

    HI,
    I am trying to grab the framebuffer in QOpenGLWidget Class. But for some reason I am getting the Empty QImage. Below is my code. I am using FrameBufferObject. Anything wrong? Because I want the pixels to render in my OpenGL context.

    saveBackBuffer()
    {
    _bSavingBackBuffer = true;

     QString fileName("C:\\Users\\ey617e\\Desktop\\yourFile.png");
     QFile file(fileName);
     file.open(QIODevice::WriteOnly);
    
     glReadBuffer(GL_BACK);
      
      makeCurrent();
      QOpenGLFramebufferObjectFormat format;
      format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
      QOpenGLFramebufferObject * fbo = new 
      QOpenGLFramebufferObject(_scrWidth, _scrHeight, format);
      fbo->bind();
      paintGL();
    
     _savedBackBuffer = fbo->toImage();
     _savedBackBuffer.save(file.fileName(), "PNG");
      fbo->release();
    

    }

    paintGL()
    {
    QOpenGLPaintDevice fboPaintDev(_scrWidth, _scrHeight);
    QPainter painter(&fboPaintDev);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

    painter.beginNativePainting();
    
    drawDisplayLists(_underIllusDisplayLists);
    drawDisplayLists(_illusDisplayLists);
    
    painter.endNativePainting();
    
    painter.end();
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Taking out your image saving code, are you getting anything rendered on your widget ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BPrasad
        wrote on last edited by
        #3

        Yes It is getting rendered.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @BPrasad said in How to grab the Framebuffer in QOpenGLWidget class.:

          QOpenGLFramebufferObject

          Are you sure that it is valid ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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