Using the code below I create a second window. I can bind the second window’s update
and draw
functions (called updateTv
and drawTv
) to the same function on the first so they will run in sync.
But I can’t seem to find a way to do the same thing with the keyboard events. When the main window is selected my app has no problem catching keyboard events, but with the second window selected, nothing happens.
I tried all kinds of combinations of ofAddListener(tvWindow->events().keyReleased(int key),mainApp.get(),&ofApp::keyReleasedTv(int key));
and similar, based on the working update
and draw
binding, but so far no luck as I’m not sure how to call the function properly.
Does anybody have some hints?
Update: looking further, the multiWindowExample
seemed useful as you can easily add a keyRelease
function to the second window, but the example doesn’t allow communication from the second window to the first it seems, so there is no way to notify the main window. I guess I’m a bit lost in the way different classes can interact.
int main( ){
// Projector window
ofGLFWWindowSettings settings;
settings.resizable = false;
settings.width = 800;
settings.height = 600;
shared_ptr<ofAppBaseWindow> projectorWindow = ofCreateWindow(settings);
settings.width = 800;
settings.height = 600;
shared_ptr<ofAppBaseWindow> tvWindow = ofCreateWindow(settings);
tvWindow->setVerticalSync(true);
shared_ptr<ofApp> mainApp(new ofApp);
ofAddListener(tvWindow->events().draw, mainApp.get(), &ofApp::drawTv);
ofAddListener(tvWindow->events().update,mainApp.get(),&ofApp::updateTv);
ofRunApp(projectorWindow, mainApp);
ofRunMainLoop();
}