tags:

views:

169

answers:

1

I've made a project with QT and OpenGl.

In QT paintGl() was repeatedly call I beleive, so I was able to change values outside of that function and call update() so that it would paint a new image. I also believe that it called initializeGl() as soon as you start up the program.

Now my question is:

I want that same functionality in a different program. I do not need to draw any images, etc. I just was wondering if there was a way to make a function like paintGL() that keeps being called so the application never closes. I tried just using a while(true) loop that kept my program running, but the GUI was inactive because of the while loop.

Any tips, other than threading preferably.

Thanks.

+1  A: 

The exact mechanism will depend on which GUI toolkit you are using. In general, your app needs to service the run loop constantly for events to be dispatched. That is why your app was unresponsive when you had it running in a while loop.

If you need something repainted constantly, the easiest way is to create a timer when your window is created, and then in the timer even handler or callback, you invalidate your window which forces a repaint. Your paint handler can then be called at the frequency of your timer, such as 25 times per second.

gavinb
How may I decide which toolkit to use? Sorry for the noob questions
NeverAgain
Assuming you keep using QT, just create a timer http://doc.trolltech.com/4.5/qtimer.html and connect the timeout signal to a slot that calls invalidate on your window. In your paint handler, you do your GL drawing.
gavinb