Hi!
I followed the discussion and I am very interested in being able to use OpenGL commands inside the paint() code of the items in my scene. Actually, I have started implementing this, with great success.
Here's a schematic overview of how I've done:
//...
//the following line adds the opengl support
//here's my item class
{
//...
{
Q_UNUSED(option);
Q_UNUSED(widget);
qWarning("OpenGLScene: drawBackground needs a "
"QGLWidget to be set as viewport on the "
"graphics view");
else{
//opengl commands here
}
}
//...
}//end-class
//...
QGraphicsScene scene;
QGraphicsView view(&scene);
//the following line adds the opengl support
view.setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers | QGL::Rgba)));
//here's my item class
class GLGraphicsItem : public QGraphicsItem
{
//...
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (painter->paintEngine()->type() != QPaintEngine::OpenGL)
qWarning("OpenGLScene: drawBackground needs a "
"QGLWidget to be set as viewport on the "
"graphics view");
else{
//opengl commands here
}
}
//...
}//end-class
To copy to clipboard, switch view to plain text mode
The ablove code works nicely and does what it shoud - if I just display the view.
Now I tried to use the view function
QGraphicsView::render ( QPainter * painter, const QRectF & target = QRectF(), const QRect & source = QRect(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio )
To copy to clipboard, switch view to plain text mode
which will output the warning message, i.e. this rendering is performed *without* opengl support.
I do not need the fastest hardware acceleration for this offscreen rendering at this point, just the opengl commends are very important for me.
Bookmarks