Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Extending leemes' answer, here is a solution which can also handle multisample framebuffer objects.</p> <p>First, if you want to draw on a QGLWidget, you can simply use the OpenGL commands leemes suggested in his answer. Note that there is a ready-to-use <code>drawTexture()</code> command available, which simplifies this code to the following:</p> <pre><code>void Widget::drawFBO(QPainter &amp;painter, QGLFramebufferObject &amp;fbo, QRect target) { painter.beginNativePainting(); drawTexture(target, fbo.texture()); painter.endNativePainting(); } </code></pre> <p>To draw multisample FBOs, you can convert them into non-multisample ones using <a href="http://qt-project.org/doc/qt-5.0/qglframebufferobject.html#blitFramebuffer"><code>QGLFramebufferObject::blitFramebuffer</code></a> (Note that not every hardware / driver combination supports this feature!):</p> <pre><code>if(fbo.format().samples() &gt; 1) { QGLFramebufferObject texture(fbo.size()); // the non-multisampled fbo QGLFramebufferObject::blitFramebuffer( &amp;texture, QRect(0, 0, fbo.width(), fbo.height()), &amp;fbo, QRect(0, 0, fbo.width(), fbo.height())); drawTexture(targetRect, texture.texture()); } else drawTexture(targetRect, fbo.texture()); </code></pre> <p>However, as far as I know, you can't draw using OpenGL commands on a non-OpenGL context. For this, you first need to convert the framebuffer to a (software) image, like a QImage using <code>fbo.toImage()</code> and draw this using your QPainter instead of the fbo directly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload