Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread Setup for GLFW

I started working with the new Lwjgl 3 which uses GLFW for its Display/mouse/keyboard handling and I'm really liking it! However today i hit a brick. I had a simple rendering animation going but when I dragged the screen it stopped rendering until i let go again.


According to: http://www.glfw.org/faq.html
The problem arises due to windows.

3.5 - Why does my application freeze when I move or resize the window?

The Windows event loop is blocked by certain actions like dragging or resizing a window, or opening the window menu. This is part of the design of Windows and cannot be changed by GLFW. If you wish to keep rendering during such actions, you should render from a secondary thread.

--http://www.glfw.org/faq.html


Ive done multi threaded things before in Java. But im not sure what goes in its own thread for this case. Should I have the opengl code and the GLFW code in seperate threads? I'm also having trouble thinking of a way to word my concerns.
like image 829
Ryuzaki Avatar asked Jul 09 '15 21:07

Ryuzaki


1 Answers

The only real restriction as far as I can find out is that GLFW needs to be in the application's main thread. This is where the OS event queue lives for GLFW and is why glfwPollEvents and glfwWaitEvents need to be in the main thread.

OpenGL rendering can be done from its own thread. glfwMakeContextCurrent ties the OpenGL context to the thread making that call. If your render function runs on it's own thread just make sure to update the context (as shown in the demo).

LWJGL Forum topic: [SOLVED] LWJGL3 Not threading as expected

LWJGL3 Multithreaded Demo referenced in the above link

like image 63
A Sammich Avatar answered Sep 21 '22 06:09

A Sammich