Glut stops running when window loses focus

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

Where are you calling glutPostRedisplay()?
Are you using glutIdleFunc or glutTimerFunc?

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)
}

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)
 }
}

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)
 }
}

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.

I see. I’ll consider using other libraries then. Thanks!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.