PDA

View Full Version : QGraphicsView + OpenGL -> Pixmap rendering issue



JoergRe
7th May 2008, 16:58
Hi folks,

here comes my first posting :)

I want to display raw data from a camera by using QGraphicsView and pixmap.
For performance issues I have to enable OpenGl, but this leads to my problem.

If OpenGL is enabled, the pixmap is getting transformed. For me it looks like the nearest neighbor algorithm for smoothing an image.

So my question:
- is it possible to disable this effect, so that QGLWidget engine is NOT antialiasing edges?

I played with QPainter::RenderHints, but no success.

Attached you'll find the source code and screenshots of the test-application. I am using version 4.3 of qt.

Kind regards
Joerg

firas
15th May 2008, 23:58
Ahoy,
Is it necessary that you use QPixmap? can you use QImage, or raw data buffer? if yes, then I recommend using glDrawPixels or better texture-mapping (http://www.qtcentre.org/forum/f-qt-programming-2/t-qt-vs-opengl-pixel-format-13048.html/?highlight=opengl)it is much faster than QT4 painting implementation in a QGLWidget.
cheers

Bitto
20th May 2008, 19:41
Try translating the image item, or setting an offset, of exactly (0.5, 0.5). This is the only way to ensure that Graphics View's untransformed logical units map perfectly to the center of each pixel in device coordinates. That should remove your smoothing effect, which is caused by OpenGL's subtexel support to cause smoothing as the pixmap is drawn at (-0.5, -0.5). QWidget (not OpenGL) does not support subtexels, so the pixmap will "snap to grid" instead of being smoothed / which is why you don't see this without enabling OpenGL. Note that OpenGL does not guarantee pixel perfection so this is highly hardware and driver dependent.

So, you can 1) translate the item:



pixmapItem->translate(0.5, 0.5);


Or 2) set an offset:



pixmapItem->setOffset(QPointF(0.5, 0.5));


Or 3) translate the view:



view->translate(0.5, 0.5);