-
I tried to create window in a background thread and got exception that the Create can be called only from the MainThread. Is it possbile to use OpenGL in a background thread? Thank you in advance! //... background thread worker
var opts = WindowOptions.Default with
{
Size = new Vector2D<int>(_width, _height),
IsVisible = false,
VSync = false,
API = new GraphicsAPI(
ContextAPI.OpenGL,
ContextProfile.Core,
ContextFlags.ForwardCompatible,
new APIVersion(4, 1))
};
var win = Window.Create(opts); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Well, there catch - you cannot run window in any different than main thread. But you can run context on different thread. In WindowOptions you need to specify flag IsContextControlDisabled as true. Then, when Load event is triggered, you create new thread in it and inside new thread create context. Then call glMakeCurrent, and do default renderloop afterwards. But do not forget to glSwapBuffers inside that custom render loop! And do anything related to OpenGL only and only inside that thread. And switch back to main, to do anything to glfw window. So, from my perspective in kinda pointless? |
Beta Was this translation helpful? Give feedback.
Well, there catch - you cannot run window in any different than main thread. But you can run context on different thread. In WindowOptions you need to specify flag IsContextControlDisabled as true. Then, when Load event is triggered, you create new thread in it and inside new thread create context. Then call glMakeCurrent, and do default renderloop afterwards. But do not forget to glSwapBuffers inside that custom render loop! And do anything related to OpenGL only and only inside that thread. And switch back to main, to do anything to glfw window.
So, from my perspective in kinda pointless?