PDA

View Full Version : Exit from game???



TolTol
03-20-2003, 01:41 AM
Hello all,

I need to allow the user to exit from a game I'm designing for college. I want to let them press Esc on the keyboard and then the game ends. I was using the exit() function to exit from the game but my supervisor wont allow this because its unstructured code.

I'm using the glutTimerFunc(...) to loop through the code and I also have a glutMainLoop(...) (although I'm not sure what this does). I'm also using Borland Builder C++ 4


I tried bypassing the glutTimerFunc(...) when the user presses Esc but the game just stops looping and is still open.

Any ideas how to exit properly???

Thanks in advance.

cbwan
03-20-2003, 03:17 AM
try with glutDestroyWindow();
i think, not 100% sure, it'll exit the program
http://www.opengl.org/developers/faqs/technical/glut.htm

"In fact, when the window is destroyed, glutMainLoop() simply calls exit(0)."

cb

nexusone
03-20-2003, 05:08 AM
The glutmainloop is the GLUT routine processing engine, it handles all call backs like window, mouse, etc. and if a call back is defind it calls that routine.

It must be called for glut to function.

That is maybe one thing missing in glut is a proper exit command.
Other then the other poster on the glut distroy window command, which I will have to test that.
Else exit is the only way to leave a glut based program.
Maybe he will let have the exit in a routine and not just a switch statment as used.


void Exit_program( void )
{
Close_files();
Kill_timer();
etc.....

exit 0;
}



Originally posted by TolTol:
Hello all,

I need to allow the user to exit from a game I'm designing for college. I want to let them press Esc on the keyboard and then the game ends. I was using the exit() function to exit from the game but my supervisor wont allow this because its unstructured code.

I'm using the glutTimerFunc(...) to loop through the code and I also have a glutMainLoop(...) (although I'm not sure what this does). I'm also using Borland Builder C++ 4


I tried bypassing the glutTimerFunc(...) when the user presses Esc but the game just stops looping and is still open.

Any ideas how to exit properly???

Thanks in advance.

Deiussum
03-21-2003, 06:40 AM
It's windows specific code, but you could always get a handle to the glut window and use SendMessage to send a WM_DESTROY message.