I have written a little OpenGL framework in the past year that i would like to extend to support multiple windows in the near future. I have an idea about what I would like to do but I am not sure if that is possible so far.
I a nutshell the inner working of my framework is as following:
- A window is created.
- A render context for that window is created.
- An application deriving from an interface is created.
window.run() is called, passing the application running in the window and the render context used as parameter.
sglr::W32Window w(nCmdShow); w.create(L"DemoApp", sglr::DISPLAY_MODE::ENUM::WINDOWED, sglr::Resolution(800, 800)); sglr::W32Rendercontext r; r.create(w, 4, 0, sglr::CONTEXT_TYPE::ENUM::DEBUG); TestApp app; return w.run(app, r);
The run method on the Win32 implementation looks like following (just some of the code):
mRunningApp->onInit();
// start message loop
while (1)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// if message is WM_QUIT, exit loop
if (msg.message == WM_QUIT)
break;
mRunningApp->onUpdate(mDt);
mRenderContext->setAsCurrent();
mRunningApp->onRender();
mRenderContext->disableAsCurrent();
}
}
What I would like to do is to create a seperate window, rendercontext and application and start a seperate main loop by calling run() just like with the first window. I already have a seperate rendercontext for each window and know about setting it active before rendering to each window.
What possible solutions would exist to do that? Just running each run() method in a seperate threads sound like a kinda naive approach to me. (I admit I already tried it with failure :D)