GlutMainLoop

Is there a way to get out of the GlutMainLoop without ending the program?

I would like to get out of the loop then perform some other code before the program ends.

Thanks!

Not sure about it, but you can work around it.
Just make an exit routine, that you can call. Then replace the current “exit’s” in the program with the new routine.

example:

void My_exit()
{
glutIdleFunc(0); // Turn off Idle function if used.
glutDestroyWindow()// Close open windows
and other close down stuff

exit //end program
}

Originally posted by BBrown:
[b]Is there a way to get out of the GlutMainLoop without ending the program?

I would like to get out of the loop then perform some other code before the program ends.

Thanks![/b]

I once looked into this and found the glut loop. It never ends. When I find the code I will post it.

I found it:

/* CENTRY */
void APIENTRY
glutMainLoop(void)
{
#if !defined(_WIN32)
if (!__glutDisplay)
__glutFatalUsage(“main loop entered with out proper initialization.”);
#endif
if (!__glutWindowListSize)
__glutFatalUsage(
“main loop entered with no windows created.”);
for (; ; ) {
if (__glutWindowWorkList) {
GLUTwindow *remainder, *work;

  work = __glutWindowWorkList;
  __glutWindowWorkList = NULL; 
  if (work) {
    remainder = processWindowWorkList(work);
    if (remainder) {
      *beforeEnd = __glutWindowWorkList;
      __glutWindowWorkList = remainder;
    }
  }
}
if (__glutIdleFunc | | __glutWindowWorkList) {
  idleWait();
} else {
  if (__glutTimerList) {
    waitForSomething();
  } else {
    processEventsAndTimeouts();
  }

#if defined(_WIN32)
// If there is no idle function, go to sleep for a millisecond (we
// still need to possibly service timers) or until there is some
// event in our queue.
MsgWaitForMultipleObjects(0, NULL, FALSE, 1, QS_ALLEVENTS);
#endif
}
}
}
/* ENDCENTRY */


As you can see, the structure is:

for (; ; )
{
}
which will never stop unless exit is called while the loop is handling its events.

I would suggest you just do what ever processing you want in your callback function and then exit. You will get the same effect as if you did it after glutMainLoop.

[This message has been edited by nickels (edited 04-02-2002).]

[This message has been edited by nickels (edited 04-02-2002).]

[This message has been edited by nickels (edited 04-02-2002).]

The problem I am having is that I have this program compiled as a DLL and when I call it from VB and it exits the DLL it ends the VB app as well? I guess it is actually performing an exit() for the whole program and not just returning from the dll.

suggestions?

I guess I found my answer in the Glut developers section. It reads as follows:

How can I make glutMainLoop() return to my calling program?

glutMainLoop() isn’t designed to return to the calling routine. GLUT was designed around the idea of an event-driven application, with the exit method being captured through an input event callback routine, such as a GLUT menu or keyboard callback handler.

If you insist on returning to your program from glutMainLoop(), there is only one way to do so. You need to download the GLUT source and hack gluMainLoop() to do what you want it to. Then compile and link into your program this hacked version of glutMainLoop(). Steve Baker has a Web site with the details on how to hack glutMainLoop() to eliminate this problem.