How to grab the Framebuffer in QOpenGLWidget class.
Unsolved
General and Desktop
-
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();
}
-
Hi,
Taking out your image saving code, are you getting anything rendered on your widget ?
-
@BPrasad said in How to grab the Framebuffer in QOpenGLWidget class.:
QOpenGLFramebufferObject
Are you sure that it is valid ?