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?
Don't call updateGL() from your timer, call update() instead to ensure that the view gets a paint event.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With