PDA

View Full Version : OpenGL in thread



c0deland
30th November 2009, 13:46
Hello.
I have a problem with a simple application. I have a window with a few widgets in it including a QGLWidget. I want to make an animation in the glwidget but everytime I start it, I cannot access the other widgets.
I also tried with threads: I made a thread which increments a value and emits a signal when done. signal is connected to a glwidget class slot which draws the opengl object into the new position. Still, the application focuses on the opengl widget and cannot access other fuctions (widgets and menu items).
Any ideea how can I solve this? I want opengl widget to redraw separately from the other widgets.... currently redrawing with updateGL().

Thanks

high_flyer
30th November 2009, 17:42
do you have a while loop or an expensive operation in your paintGL()?

john_god
30th November 2009, 21:13
did you use timers ?

c0deland
1st December 2009, 15:47
do you have a while loop or an expensive operation in your paintGL()?

This is my paintGL:


void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0, 0.0, -10.0);
glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
glCallList(object);

}
It's the hellogl's paintGL from examples, modified to rotate on Y with a certain angle, increment 1.

c0deland
1st December 2009, 15:50
did you use timers ?

I tried with timers and now it works. This is what I have in the thread now:

void GLThread::start_simulation()
{
connect(simtimer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
simtimer->start(1);
}

where:

void GLThread::rotateOneStep()
{
i=i+Tspeed;
emit changeVal(i);
}
changeVal signal is connected with the openGL function which executes the rotation and has the updateGL() at the end.

Is this the only way to do this? or is it the best way?

john_god
3rd December 2009, 00:32
I'm not sure but I think you should put glClear(...) in the initializeGL() function.
No need to keep calling it in paintGL() as you update drawings.