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. [SOLVED] - Save and Draw FrameBufferObject from paintEvent
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] - Save and Draw FrameBufferObject from paintEvent

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.4k 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.
  • F Offline
    F Offline
    fredQt
    wrote on last edited by
    #1

    Hello everybody,

    I am new using QGLWidget and frameBufferObjects. I have been reading about framebuffer objects because I need overpaint a GL (never to erase the previous GL) and paint some text and lines with QPainter.
    The only solution that I found was use framebuffer to save the GL and then paint the framebuffer with a QPainter, but it's not working.
    I really need a little help please.

    I add the pseudocode:

    @NewClass::NewClass(QWidget *parent): QGLWidget(QGLFormat(QGL::SampleBuffers), parent){
    m_frameBuffer = new QGLFramebufferObject(500, 500, QGLFramebufferObject::Depth);
    (QImage m_savedImage is defined in the class definition)
    }

    void NewClass::ogldraw(){
    // I use the frameBufferObject for painting the current GL draw
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    m_frameBuffer->bind();
    glBegin(GL_POINTS);
    ...
    glEnd();
    m_frameBuffer->release();
    }

    void NewClass::paintEvent(){
    // I use m_savedImage for overpainting the next GL draw to all previous overpainted draw
    QPainter painterToSavedImage(&m_savedImage);
    painterToSavedImage.setCompositionMode(QPainter::CompositionMode_SourceOver);
    painterToSavedImage.drawImage(0, 0, m_frameBuffer->toImage(), Qt::TransparentMode);

    // I try to show the overpainted frameBufferObject
    QPainter painterW(this);
    painterW.setCompositionMode(QPainter::CompositionMode_SourceOver);
    painterW.drawImage(0, 0, m_savedImage,Qt::TransparentMode);
    

    }@

    I don't know why the ogldraw() always draw to screen even if I don't use updateGL neither repaint.
    Why the m_frameBuffer drawn into m_savedImage is not working?

    Please I want to learn why I don't get the expected result.

    Thanks,

    Fred

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fredQt
      wrote on last edited by
      #2

      I got it.
      The makeCurrent context must be set in the constructor or in the initializeGL.

      Fred

      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