close program and exit

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?

capture WM_CLOSE


case WM_CLOSE:
    PostQuitMessage(0);break;

i’m working on linux…

We need more information. How do create your opengl window? Using glut?

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

So you are forking! That’s a piece of information. :slight_smile:

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…

child implement openGL function and parent manages GTK GUI

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.

can you give me an example?