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);
As you can see. The image that have the visual(wich is my main window) works just fine.
but the window that i´ve open programatically does not render the fbos allthought it renders the drawings that @Daan uses as an example.
is this because i can´t set settings.shareContextWith if i try to do it inside the ofapp? So, im making the question that @sinsynplus make. Is it posible to set settings.shareContextWith inside my ofApp?
and if it is posible, is this the reason why my fbos with shaders are not being drawn in the second window?
fbos can’t be shated between windows but you can share a texture between them. So if you create an fbo in one window you can’t draw on it from the other but you can draw it’s texture in the other.
In order to allow that though you need to share the context by using:
settings.shareContextWith = mainWindow;
where mainWindow is the window you get when calling ofCreateWindow in main, since it’s a shared pointer you can store a copy in your application for example to use it later
But how to have a pointer to the mainWindow if I creating the windows inside my ofApp an NOT in the main?
I mean, I should get a pointer to the same ofApp instance inside a ofApp instance function. Is there any way to set settings.shaderContextWith NOT in the main buy inside the offapp.cpp ?
Do you now if there is a way to get the keypressed and mousepressed and mouse positions that i´ve made in the programatically created windows!? Like listen to keypressed and mousepressed but from the windows that are being generate.
And also. Is there any way to get a listener when that window is closed?
Because it seems like the my windows vector keeps having the pointers of the windows that i´ve closed.
also : I want to point that it work using :
std::shared_ptr<ofAppBaseWindow> mainWindow;
and not
std::shared_ptr<ofGLFWAppWindow> window;
ofGLFWAppWindow is not recognized as an object in my ofApp.h
you can also simply call ofRunApp(newWindow, otherApp)where otherApp is a new class that implements ofBaseApp and OF will hook up all the events for you.
The pointers of course won’t magically disappear from the vector you need to listen to the exit event for the newly created window and remove it’s pointer from the vector when it’s about to exit
also take a look at the example multiWindowExample, everything in there works no matter if the window is created from main or anywhere else