Reputation: 33579
I’m drawing a simple scene with Open GL. I’ve subclassed QGLWidget and overriden paintGL(). Nothing fancy there:
void CGLWidget::paintGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (120.0, 160.0, -300.0, 0.0 + 120.0, 0.0 + 160.0, 2.0 - 300.0, 0.0, 1.0, 0.0);
glScalef(1.0f/300.0f, 1.0f/300.0f, 1.0f/300.0f);
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80.0, width()/(double)height(), 5.0, 100000.0);
glMatrixMode(GL_MODELVIEW);
glBegin(GL_POINTS);
glColor3f(1.0f,0.6f,0.0f);
glVertex3d(x, y, z);
// ...drawing some more points...
glEnd();
}
I have a timer in main window which triggers updateGL()
of GL widget. I’ve verified that it results in paintGL()
being called. However, the actual picture on the screen is only updated very rarely. Even if I resize the window, scene is not updated. Why is that and how can I force it to update?
Upvotes: 6
Views: 15643
Reputation: 1421
inside your CGLWidget constructor
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(10);
timer -> start(VALUE);
play with `VALUE 10 is just an example.
Adorn
Upvotes: 6
Reputation: 4812
Don't call updateGL() from your timer, call update() instead to ensure that the view gets a paint event.
Upvotes: 14