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:

  1. A window is created.
  2. A render context for that window is created.
  3. An application deriving from an interface is created.
  4. 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):


        // start message loop
        while (1)

            while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))



            // if message is WM_QUIT, exit loop
            if (msg.message == WM_QUIT)







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)


1 Answer 1


I think you mis-designed your API. Why does a window take an app, instead of an app taking multiple windows?

An application can have multiple windows, but a window can only belong to one application.

If you change this around there will be no need for multiple run loops. There will just be one in the application, and the application will handle events and dispatch rendering calls etc. for each window.

  • \$\begingroup\$ When I started with the implementation I first didn´t had multiple windows in mind to be honest. I thought about your idea as well and it would work better with multiple windows indeed. Unfortunately my whole "app principle" would not work as planned anymore and there would be more work to do within the app like processing input, polling message etc. But maybe I can work something out. Thanks for your suggestion :) \$\endgroup\$
    – Chris
    Commented Jan 15, 2015 at 15:38
  • \$\begingroup\$ Maybe you also misnamed the App class. Maybe you really have an App instance (takes care of main loop), multiple Window instances (take care of only their own input, passed to them by the App) and a Game instance (takes care of logic, rendering etc)? \$\endgroup\$
    – bogglez
    Commented Jan 15, 2015 at 18:00
  • \$\begingroup\$ Well polling new events is still part of the platform dependant implementation of the window. So I would rather poll the events within the app´s mainloop from the current active window. \$\endgroup\$
    – Chris
    Commented Jan 16, 2015 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .