Skip to main content
gamedev.net
🔒 Locked

exit open gl program???

Started by Squirrel 3 replies 450+ views
Original Post
Squirrel
Squirrel
I made an autorun for a game which starts up as open gl animation, then while it''s animated, a dialog box will come with the options. When any button is pressed, the dialog box closes, how do I close the open gl program also. Note that this code will be written from a win api''s case statement. Any commands that close Open gl? Also, while the dialog is up,how do I keep on animating the sceene. Do I just call the draw sceene from the win api main switch statement? Thanks!
Ryan
Fruny
Fruny
quote:
Original post by Squirrel
I made an autorun for a game which starts up as open gl animation, then while it''s animated, a dialog box will come with the options. When any button is pressed, the dialog box closes, how do I close the open gl program also. Note that this code will be written from a win api''s case statement. Any commands that close Open gl?



exit() terminate any program.

quote:

Also, while the dialog is up,how do I keep on animating the sceene. Do I just call the draw sceene from the win api main switch statement? Thanks!


You''ve got to alter your message pump. Check the tutorials.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Squirrel
Squirrel
quote:

You''ve got to alter your message pump. Check the tutorials.





Thanks for the exit(); function. I''ll be using that allot now. In any situation, this will conquer the thoughest ways to get out.

For the mesage pump thing, what tutorials are you refering to? I tried to call the draw sceen inside the message loop but since the loop is typed before the draw scene, it does not find the function.

Thanks!

Ryan
Prosper/LOADED
Prosper/LOADED
quote:
Original post by Squirrel
For the mesage pump thing, what tutorials are you refering to?



NeHe''s tutorials are great.

quote:

I tried to call the draw sceen inside the message loop but since the loop is typed before the draw scene, it does not find the function.



You must use a prototype. You should know that kind of things before writing Win32/OpenGL programs (read C/C++ books a bit more). Anyway, a prototype is a way to tell the compiler that your function actually exists and how it must call it. Here''s an example :

  
int drawGL(); // See ? no code here


void aFunction()
{
...
drawGL(); // this will work

...
}

int drawGL()
{
...stuff...
}

Aprosenf
Aprosenf
If you''re going to use the exit() function, then another function you might want to check out is the atexit() function. What it does is, you pass it a function pointer, and when your program terminates, either by returning from WinMain() or by calling exit(), it will call the function you registered with atexit(). You can register up to 32 functions, and they are called in the reverse order in which they were registered. Also, all functions registered must have no return value or arguments; i.e. they''re void func(void) types of functions. So, you could do the following:
  
void SomeFunction(void)
{
atexit(func1);
atexit(func2);

if(someCondition)
exit(EXIT_SUCCESS);
else if(otherCondition)
exit(EXIT_FAILURE);
}

void func1(void)
{
MessageBox(NULL, "Inside func1()", "atexit()", MB_OK);
}

void func2(void)
{
MessageBox(NULL, "Inside func2()", "atexit()", MB_OK);
}

Whenever this program terminated, either by finishing WinMain or by calling either of the two exit()''s from SomeFunction(), it would pop up a message box displaying "Inside func2()" and then another message box displaying "Inside func1()".

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.