EDIT: IS there any pre-built libraries to do this for me, that either uses SDL OR runs on Window, Linux, Mac, iOS and Android?
At the moment, I am not sure if the way I am changing contexts is quite a good design, I haven't completely finished it. I'm just really concerned about wasting my time. I am using SDL for Window management, and event handling.
I currently wrap SDL (specifically SDL 2) in classes to manage this. These are my classes and what they do:
- Window - Describes a Window
- WindowContext - Describes a context for the Window (abstract class)
- WindowDelegate - Used to determine when the context has changed, when the window will open/close, etc.
- WindowEventListener - Listens to events from the Window (not sure if I should just stick to polling instead of call back functions)
Anyway, here's an example of how it works:
OglWindowContext* context = new OglWindowContext;
// change context's settings
Window window(ipoint2(), idimension2(640, 480), "Test Window",
Window::Resizeable, context, &windowListener,
NULL /* window delegate */);
while(window.isOpen())
{
window.processEvents(); // calls back events to the WindowEventListener
window.draw(); // calls the context's draw method
}
NOTE: ipoint2 is a 2d point
And I can change the context midway by calling:
window.setContext(new Dx9Context); // or whatever context you would like
Is there any easier way, or should I say more efficient way, to do this?