You can use from the mouse or keyboard functions to delete the object. As an example:
void mouse( int btn, int state, int x, int y )
{
if( btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
{
ExitFromPogram();
}
And your ExitFromProgram can be in this form:
void ExitFromProgram()
{
if( object )
free object;
exit(0);
}
In your previous code, you never can free the object, since it has been called after your glutMainLoop().If you free the object before the glutMainLoop(), you never can use from that object in your program, since it is deleted in the first loop.none-glut functions in your main function are executed only in the first loop.
RigidBody, simply because atexit has been redefined in the C++ standard library, so might not provokes some mistakes due to a C-only function call. As you know C and C++ are no longer 100% compatible. This is almost true for the standard library.
VinceDeNice, I don’t know why at_exit doesn’t work, maybe because it is called atexit and not at_exit . It’s defined in cstdlib if I’m not wrong.
I just searched in MSDN. Yes it is atexit and is defined at <stdlib.h>
Libraries:
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
-Ehsan-