PDA

View Full Version : Glut stops running when window loses focus



tchau83
09-26-2010, 08:56 AM
Hi,

I'm coding a program which is something like a simulation and the results are rendered in real time. I'm using GLUT to create the display window. Since the main program should be running the whole time, the program is called once using glutDisplayFunc(). The program will use OpenGL functions to render, swap buffers etc and call exit() to terminate everything when it finishes.

The problem is that when the glut window loses focus (eg, i click on another window), the glut window stops updating, even though the simulation is running OK. The program is coded using MSVC and ran in windows XP. However, when I run the program in Windows 7, the window updates just fine.

Can anyone explain why the window stops updating, and is there any solution for that?

Thank you

marshats
09-26-2010, 11:30 AM
Where are you calling glutPostRedisplay()?
Are you using glutIdleFunc or glutTimerFunc?

tchau83
09-26-2010, 11:20 PM
I'm using none of those glut functions. The program is like this..

int main(){

glutInit() functions
glutCreateWindow()
glutDisplayFunc(runProgram)
glutMainLoop()

}

void runProgram(){
...
while(simulation not finished)
{
...
glBegin()
...
glEnd()
glutSwapBuffers()
}
...
exit(1)
}

ZbuffeR
09-27-2010, 07:02 AM
Glut is event-driven.
You should do it frame by frame, like this, to allow normal operations :



glutDisplayFunc(drawFrame);


...

void drawFrame(){
...
if(simulation not finished) {
...
glBegin()
...
glEnd()
glutSwapBuffers()
glutPostRedisplay()
...
} else {
exit(1)
}
}

tchau83
09-27-2010, 08:44 AM
Yes, but I do not need any user interaction. I'm using Glut merely to create a window to render to.

Also, it would be difficult to code the simulation so that it stops halfway, and then when called again by drawFrame() continues from the previous operation. There's also an uncertainty on the frequency runSimulation will be run.



glutDisplayFunc(drawFrame);
...

void drawFrame(){
...
if(simulation not finished) {
//runSimulation code
...
glBegin()
...
glEnd()
glutSwapBuffers()
glutPostRedisplay()
...
} else {
exit(1)
}
}

ZbuffeR
09-27-2010, 09:59 AM
Don't use glut then :whistle: ...
You have to understand that we explained exactly "why the window stops updating".

So either you use Glut properly, or use something else.
Ie. GLFW seem more suited for your case.



There's also an uncertainty on the frequency runSimulation will be run.
That is already what happen with your current code.

tchau83
09-28-2010, 01:27 AM
I see. I'll consider using other libraries then. Thanks!