Sharing context with two ofApp in multiwindow

in the scenario someone might want to open close a second window multiple times while sharing a context with that particular window

…but also have a new ofApp to access key/mouse/drag/ events

will this implementation be problematic?

its seems to be behaving nicely…


can be called as many times without leaking or having other weird behavior right?

Hi Kkkkkk,

I’m very interested by this.
I’m trying to get different windows poping up depending on the amount of glfwGetMonitors detected.

I don’t have an answer, but I’d figured I would post here since it’s related to your topic…

I tried replicating your code, but I’m missing stuff:

How do you create a settings_menu_sms_schedule ?
Is it extending a ofAppBaseWindow or ofBaseApp or something else?

How come you don’t have to use shareContextWith as described here, to share the components?

Sorry if this is a bit confusing, it’s a bit opaque for me…



Hi, that is just an extern bool
I call it as true when the window is running and false from the exit or the destructor of the second window

This is just to know when I closed the second window and to be sure only one is running… Though it shouldn’t matter

The code works fine thus far

By the way I am sharing context:

I do it from the main function:

settings.shareContextWith = sms_scheduler; 

I mean there are many ways to do this, in this example I went with the most simple and straight forward way.

1)I declare the second ofApp class UNDER the first of App.

this way the first ofApp window can have a pointer of the second window (in my example I call the window mainWindow because is a bigger window but in reality it’s the secondary :wink:

and the second window can have a pointer of the main ofApp


ofApp * _sms;

in the main ofApp:

shared_ptr<ofAppBaseWindow> mainWindow;//i am really the second window
ofGLFWWindowSettings settings;

Notice that I also have a “ofGLFWWindowSettings” thingie over there

This is becaue in main() I want to pass pointers of those two things so I can then pass them to the second window.

settings.shareContextWith = sms_scheduler; 
mainApp->settings =settings;

when I close the first window I close the second window as well if it’s open
via calling setWindowShouldClose(); in ofApp::exit():


settings_menu_sms_schedule_is_open is just an extern bool, I call it false when window is not open and true if it is, most people hate extern bools. you might use a shared pointer etc…

hope things are more clear now…

1 Like


Yes this is more clear, thanks for explaining.