Multi Windows, open/close it programatically. Is there a way?


Hi guys,

Been looking to the new multi window feature in OF for a possible project. It’s pretty cool that now you can set multiple windows so easily.

I just wonder one thing, after closing the window is there a way to open it again programatically?



Hey, that’s a complex question to answer, it depends on your specific needs.
Raven Kwok has recently done some experiments with windows using Processing.

Looking at the multiWindowOneAppExample, I just tried making them on the fly from the main ofApp and it seems to run stable.


std::vector<shared_ptr<ofAppBaseWindow> > windows;
void drawRandomInWindow(ofEventArgs & args);


	void ofApp::keyPressed(int key){
		ofGLFWWindowSettings settings;
		settings.width = 300;
		settings.height = 300;
		settings.resizable = false;
		windows.push_back( ofCreateWindow(settings) );

		ofAddListener(windows.back()->events().draw, this,&ofApp::drawRandomInWindow);

	void ofApp::drawRandomInWindow(ofEventArgs &args){
		ofDrawRectangle(ofRandomuf()*20.f, ofRandomuf()*20.f, ofRandomuf()*80.f, ofRandomuf()*80.f);

	// add to ofApp::setup() to manipulate created windows
	for(auto it=windows.begin(); it!=windows.end(); it++){
		ofDefaultVec2 pos(150+cos(fmod(ofGetElapsedTimef(),TWO_PI)) * 100.f, 150+sin(fmod(ofGetElapsedTimef(),TWO_PI)) * 100.f);
		(*it)->setWindowPosition(pos.x, pos.y);


Hi @Daan,

Awesome, thanks a lot for the insight :slight_smile:


awesome indeed… thanks a lot…

is it also possible to do…
settings.shareContextWith = mainWindow;
with this method?
or how can i access/refer to windows created in main.cpp?

and how is it possible to identify different elements of the vector with the “auto it” method?




You have either to register the window instances from your ofApp (not in main.cpp), store them, then loop trough them to send commands.

In the example above, when you press a key, windows is populated with a new window instance.
The last piece of code in my example above shows how to loop trough them and call a member function on each (setWindowPosition).

Another way to communicate is to listen to window events.
ofAddListener(windows.back()->events().draw, this,&ofApp::drawRandomInWindow);


thanks a lot… sorry for my late reply… did not login for quite a long time…
so you are not doing any window related stuff in main.cpp?