[SOLVED] - Save and Draw FrameBufferObject from paintEvent
-
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
-
I got it.
The makeCurrent context must be set in the constructor or in the initializeGL.Fred