PDA

View Full Version : QGraphicsView animation performance



rakkar
2nd September 2009, 05:31
I want to display an animated image with QGraphicsView. The animated image will play at 30 frames per second, and I will have multiple images at the same time. One way to do it is to have a list of QGraphicsPixmapItem, and keep feeding that to QGraphicsScene. But that seems inefficient. Is there any better way to do this that I'm missing? Maybe I should access the OpenGL device directly?

wysota
2nd September 2009, 08:43
If your viewport is OpenGL based then you can use OpenGL calls to render your item.

rakkar
2nd September 2009, 16:34
All I'm trying to do is render a triangle and a square (from here http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02 ) , but the viewport is always black.

VisualizationWindowClass is just a blank dialog from QtDesigner



class VisualizationWindow : public VisualizationWindowClass, public QGLWidget
{
virtual void initializeGL(){
qglClearColor(Qt::black);
glShadeModel(GL_FLAT);
}
virtual void resizeGL( int w, int h ){
glViewport( 0, 0, (GLint)w, (GLint)h );
}
virtual void paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad

}

}

wysota
2nd September 2009, 19:57
So are you using Graphics View or not?

rakkar
2nd September 2009, 20:02
It doesn't seem to be necessary. The system can just display a QGLWidget. If I change the clear color it displays a different color for example. It just doesn't draw anything else.

wysota
2nd September 2009, 20:50
If all you want is a triangle and a square, I'd use QPainter instead of pure OpenGL calls. You can render on QGLWidget if you want of course...

rakkar
2nd September 2009, 21:11
If all you want is a triangle and a square, I'd use QPainter instead of pure OpenGL calls. You can render on QGLWidget if you want of course...

Thanks but that's not what I want. I'm just demonstrating that even the simplest case doesn't work.

wysota
2nd September 2009, 21:22
It doesn't work probably because your viewport is setup incorrectly. Go to link you provided, scroll down and download the sources fot C++/Qt. You'll see they set up the modelview matrix too.

rakkar
3rd September 2009, 04:14
It doesn't work probably because your viewport is setup incorrectly. Go to link you provided, scroll down and download the sources fot C++/Qt. You'll see they set up the modelview matrix too.

Fantastic, thanks for pointing that out.