The following is the code for my widget which subclasses QOpenGLWidget. What should be happening is that the framebuffer object flashes between white and black between each frame, but it only displays white, which tells me it's rendering once and then never updating.
void GLWidget::paintEvent(QPaintEvent *event)
{
QRect sourceRect(0, 0, 320, 240);
QSize sourceSize = sourceRect.size();
QOpenGLFramebufferObject sourceBuffer(sourceSize);
sourceBuffer.bind();
QOpenGLPaintDevice device(sourceSize);
QPainter sourcePainter;
sourcePainter.begin(&device);
static bool flash = true;
if (flash)
{
sourcePainter.fillRect(sourceRect, QBrush(Qt::white));
}
else
{
sourcePainter.fillRect(sourceRect, QBrush(Qt::black));
}
flash = !flash;
sourcePainter.end();
sourceBuffer.release();
QPainter destinationPainter;
destinationPainter.begin(this);
destinationPainter.setRenderHint(QPainter::Antialiasing);
destinationPainter.fillRect(event->rect(), QBrush(Qt::black));
int destinationWidth = event->rect().width();
int destinationHeight = event->rect().height();
QImage sourceImage = sourceBuffer.toImage();
//sourceImage.save(&process, "bmp");
QImage scaledSourceImage = sourceImage.scaled(destinationWidth, destinationHeight, Qt::KeepAspectRatio);
int translationX = destinationWidth - scaledSourceImage.width();
int translationY = destinationHeight - scaledSourceImage.height();
destinationPainter.translate(translationX / 2, translationY / 2);
destinationPainter.drawImage(0, 0, scaledSourceImage);
destinationPainter.end();
}
Am I using the framebuffer object correctly here? Also is there a more appropriate way to draw something offscreen and then display it in a QOpenGLWidget?