#include "fbotest.h" #include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); GLWidget w; w.show(); return a.exec(); } GLWidget::GLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), source(0), multisampleBlit(0) { } void GLWidget::resizeEvent(QResizeEvent *ev) { makeCurrent(); delete source; delete multisampleBlit; QGLFramebufferObjectFormat format; format.setAttachment(QGLFramebufferObject::NoAttachment); format.setSamples(4); format.setInternalTextureFormat(GL_RGBA16F); source = new QGLFramebufferObject(ev->size(), format); // random output: multisampleBlit = new QGLFramebufferObject(ev->size()); // just black: // multisampleBlit = new QGLFramebufferObject(ev->size(), format); QRect rect(QPoint(0, 0), source->size()); QPainter painter(source); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(rect, Qt::transparent); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.fillRect(0, 0, 100, 100, QColor(0, 127, 0, 127)); painter.drawText(rect, Qt::AlignCenter, "Test"); } void GLWidget::paintEvent(QPaintEvent *) { makeCurrent(); QPainter painter(this); painter.fillRect(rect(), QColor(255, 0, 255)); if (!source) return; QGLFramebufferObject::blitFramebuffer(multisampleBlit, rect(), source, rect()); drawTexture(rect(), multisampleBlit->texture()); }