[Qt-interest] Creating QUAD Elements would openGL be better than Qt
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Fri Oct 16 13:44:51 CEST 2009
Sujan Dasmahapatra wrote on Friday, October 16, 2009 1:12 PM:
> ...
> I basically want to display some elements ,i.e QUAD elements these
> elements will be graphics. Would be Qt best for this or OpenGL
> graphics would be better option.This is not 3D graphics but 2D.
It probably depends on how many quad elements you want to draw. If a couple of hundreds, the speed achieved by the QPainter might already be satisfactory for your purpose (assuming you don't need a constant update at say 30 FPS or so).
Also note that you can use the QPainter API on top of a QGLWidget, so the corresponding commands (drawing lines, rectangles etc) are automagically converted to the appropriate glLine(), glRect(), ... calls! The advantage of using the QPainter API is that you don't need to learn (use) another API. Programmers can stick to the well-known "Qt API conventions" and "feel of use".
If on the other hand you require "real-time do-it-as-fast-as-possible-but-faster-than-that"-requirements and you really want to optimise with your own GL commands, then yes, go for the QGLWidget + OpenGL API approach.
As a side-note: the GL_QUADS primitive (as in glBegin(GL_QUADS); ....; glEnd();) has been DEPRECATED in OpenGL 3.0, see for example:
http://eve.uj.ac.za/ag2009/agkeynotes/The%20Khronos%20APIs.pdf
(page 29).
so you need to use triangles - piece of cake; I just mention this because you were specifically using the word "QUAD" ;)
> Do I
> need to replace QGraphicsView by QGLWidget to display openGL graphics
Yes, whenever OpenGL is to be involved - be it via the Qt API, e.g. QPainter, or with OpenGL commands itself - you need to draw on top of a QGLWidget! As always, refer to the Qt docs on how to do this:
"By default, QGraphicsView provides a regular QWidget for the viewport widget. You can access this widget by calling viewport(), or you can replace it by calling setViewport(). To render using OpenGL, simply call setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport widget."
http://doc.trolltech.com/4.5/qgraphicsview.html#details
See also the explanatory OpenGL Qt examples and demos (especially the "40'000 chips demo" might be insightful, to get you some feeling for the possible performance gain):
http://doc.trolltech.com/4.5/demos-chip.html
http://doc.trolltech.com/4.5/examples.html#opengl
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list