Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use GLUT not in main thread on OS X?
    primarykey
    data
    text
    <p>I once tried to open a GLUT window from a sub-thread and got lots of nasty problems. I remember this post on lists.apple.com:</p> <pre><code>GLUT functions may only be called from the application's main thread </code></pre> <p>Has anything changed in this regard with GLUT on Mac OS X ? Is there a thread-safe GLUT that let's you open windows from any thread ?</p> <p>If GLUT is not an option, is there a tiny library that replaces GLUT and would work from any thread ?</p> <p><strong>[edit]</strong></p> <p>Here is the result of my tests triggered by the various solutions proposed as answers:</p> <ul> <li>GLFW looked nice but did not compile (current branch is 3 years old)</li> <li>Agar was another pretender but it's too big for the tiny need I had</li> <li>SDL is not BSD-license compatible and it's a huge library for code that should fit on a single file</li> <li>GLUT cannot run in any thread.</li> </ul> <p>I decided to reinvent the wheel (yes, that's good sometimes) and the final class is just 200 lines of code. It let's me open and close a window from any thread (openGL draw in new thread) and I have full control on vertical sync and such (SDL uses double buffering = slow for openGL). I had to trick around the <code>NSApp</code> to properly start and stop the application (which does not use an event loop otherwise).</p> <p>To those telling me that OpenGL is not thread-safe, that's not exactly true: you can run multiple OpenGL threads and the draw commands will be executed in the OpenGL state assigned to that thread. OpenGL is <strong>thread-specific</strong>.</p> <p>If anyone needs some bare-bones code to create OpenGL windows using Cocoa: <a href="http://github.com/rubyk/rubyk/blob/master/src/lib_objects/gl_window/macosx/gl_window.mm" rel="nofollow noreferrer">gl_window.mm</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload