Search code examples
macosopenglglutlibdispatch

How to use GLUT with libdispatch?


Both GLUT and libdispatch have their own event-handling loops, which are invoked with functions that never return: glutMainLoop(); and dispatch_main();, respectively.

I've tried:

dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(q, ^{
    glutMainLoop();
});

dispatch_main();

...and the window displays, but does not respond to any events or redraw after the initial call to the function specified with glutDisplayFunc().

How can I get GLUT and libdispatch to play nicely together?


Solution

  • You can't. Both of them want to own the message processing loop. And since there's only one such loop, they can't both own it.

    If you used FreeGLUT, you could find a way to make that work. But a better alternative would be to just use GLFW.