Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to draw QGLFrameBufferObject onto the painter from within QGraphicsItem::paint()
    primarykey
    data
    text
    <h1>Small version of my question</h1> <p>In a QGraphicsItem::paint() function I have a QGLFrameBufferObject. How do I get it on the paintdevice of the painter that is passed as an argument? (provided that the QGraphicsItem is in a scene that is being rendered by a QGraphicsView that has a QGLWidget as viewport => painter is using opengl engine)</p> <pre><code>QGraphicsItem::paint(QPainter* painter, ...) { QGLFramebufferObject fbo; QPainter p(fbo); ... // Some painting code on the fbo p.end(); // What now? How to get the fbo content drawn on the painter? } </code></pre> <p>I have looked at the framebufferobject and pbuffer examples provided with Qt. There the fbo/pbuffer is drawn in a QGLWidget using custom opengl code. Is it possible to do the same thing within a paint() method of a QGraphicsItem and take the position of the QGraphisItem in the scene/view into account?</p> <h1>Big version of my question</h1> <h2>Situation sketch</h2> <p>I have a QGraphicsScene. In it is an item that has a QGraphicsEffect (own implementation by overriding draw() from QGraphicsEffect). The scene is rendered by a QGraphicsView that has a QGLWidget as viewport.</p> <p>In the QGraphicsEffect::draw(QPainter*) I have to generate some pixmap which I then want to draw using the painter provided (the painter has the QGLWidget as paintdevice). Constructing the pixmap is a combination of some draw calls and I want these to be done in hardware.</p> <p>Simplified example: (I don't call sourcepixmap in my draw() method as it is not needed to demonstrate my problem)</p> <pre><code>class OwnGraphicsEffect: public QGraphicsEffect { virtual void draw(QPainter* painter); } void OwnGraphicsEffect::draw(QPainter* painter) { QRect rect(0,0,100,100); QGLPixelBuffer pbuffer(rect.size(), QGLFormat(QGL::Rgba)); QPainter p(pbuffer); p.fillRect(rect, Qt::transparent); p.end(); painter-&gt;drawImage(QPoint(0,0), pbuffer-&gt;toImage(),rect); } </code></pre> <h2>Actual problem</h2> <p>My concerns are with the last line of my code: pbuffer->toImage(). I don't want to use this. I don't want to have a QImage conversion because of performance reasons. Is there a way to get a pixmap from my glpixelbuffer and then use painter->drawpixmap()?</p> <p>I know I also can copy the pbuffer to a texture by using :</p> <pre><code>GLuint dynamicTexture = pbuffer.generateDynamicTexture(); pbuffer.updateDynamicTexture(dynamicTexture); </code></pre> <p>but I have no idea on how to get this texture onto the "painter". </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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