PDA

View Full Version : close program and exit



trackin
07-24-2009, 03:18 AM
when I close openGL window the program still runs until I press ctrl+c. how can I close automatically the program without press ctrl+c?

Ilian Dinev
07-24-2009, 05:21 AM
capture WM_CLOSE


case WM_CLOSE:
PostQuitMessage(0);break;

trackin
07-24-2009, 06:17 AM
i'm working on linux...

dletozeun
07-24-2009, 06:31 AM
We need more information. How do create your opengl window? Using glut?

trackin
07-24-2009, 10:03 AM
static void create_frame_cube(GtkWidget *window){
int returned = fork();
if(returned != 0){
glutInit(&argc_, argv_);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutKeyboardFunc(processNormalKeys);
SetupRC();
glutMainLoop();
}
}


void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void SetupRC(void){
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}

void processNormalKeys(unsigned char key, int x, int y) {
if (key == 27)
exit(0);
}

I want exit with x window button pressing and free all resources. I have a GTK GUI with different command and I create a new process for the openGL program

dletozeun
07-24-2009, 11:59 AM
So you are forking! That's a piece of information. :)

I guess you do not really know how forking work in unix based systems or the create_frame_cube function code is not complete.

Parent and child processes have to be synchronized and I see only one code path for the child process in the create_frame_cube function...

trackin
07-24-2009, 01:11 PM
child implement openGL function and parent manages GTK GUI

dletozeun
07-24-2009, 02:32 PM
Ok but as I*said, it seems that in the provided code, there is only the opengl path.
To make your program quit properly you have to kill the child process first then the parent.
In the gtk process when you catch the close event call the kill( pid, SIGKILL ) function with the child pid to kill the opengl process.
Also register a signal handler in the child process (opengl one) with the signal() function to handle the kill signal and release all allocated ressources.

trackin
08-05-2009, 03:11 AM
can you give me an example?