Search code examples
cmacosopenglgraphicsglut

How do I set the close operation on a GLUT program written in C? (as in the red button in the top left corner to work)


I'm writing a really simple program using GLUT and C in XCode 4.2.

int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);

    glutCreateWindow("GLUT Program");

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);

    glutMainLoop();
    return EXIT_SUCCESS;
}

When the window opens up, I can't close it via the red button in the top left corner (Mac) because it is grayed out. If any Java programming I've done is a model, there should be some function that sets the close operation so that the red exit button works. I also can't seem to find the documentation for the most recent version of GLUT. Whenever I google it I seem to get OpenGL documentation, which makes me a little more confused then I was on the relationship between the two (I thought GLUT was a cross-platform interface to interact with OpenGL).


Solution

  • If you want to use the Mac's windowing system to write a native Mac-like application (and you should - your users will thank you!), you should be using NSOpenGLView instead of GLUT. There's some good sample code here.