PDA

View Full Version : QGraphicsScene OpenGL rendering



nelisdnurste
26th April 2011, 11:01
Hi forum,

I'm currently making a pong game, I heard that using openGL rendering can reduce the load on the CPU and direct it to the GPU. Im using the QGraphicsScene as my 2D gameworld. Does anyone know how to let QGraphicsScene use OpenGL while rendering the graphics?

Thanks in advance,

Niels

dkoryagin
26th April 2011, 11:11
something like this:

ui->mapView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers | QGL::DirectRendering)));
ui->mapView->setViewportUpdateMode(QGraphicsView::SmartViewport Update);
ui->mapView->update();

rtfm =)

nelisdnurste
26th April 2011, 11:39
I'd like a normal response, and it isn't in the manual

user14921
9th October 2011, 00:09
http://doc.qt.nokia.com/qq/qq26-openglcanvas.html

mpita
9th October 2011, 10:02
You can add a QGLWidget as viewport of your graphic view. Example:



myGraphicsView->setViewport(new QGLWidget());


This enable the GL acceleration while drawing your scene.

You can also specify what kind of options must be enabled, and you can do this through QGLFormat parameter, as said dkoryagin:



myGraphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers | QGL::DirectRendering)));


You'll find all the available Format options (that at the moment I don't remember) here. Warning, is the manual :P :

http://doc.qt.nokia.com/stable/qgl.html#FormatOption-enum


Ciao,
Marco