Multiple windows using GLFW

Here’s an addon which modifies the GLFW window class for multiple windows and events:

Awesome thanks @charlesveasey great addon! just FYI I had to change ofxMultiGLFWWindow.cpp to objective C++ source in Xcode to get it to compile for anyone else looking to get this running. Thanks again!

Thanks. I updated the readme with the Xcode instruction.

i’m getting an error: “/Volumes/Work/Tools/openFrameworks/of-github-081/libs/glfw/include/GLFW/glfw3.h:2122:20: Candidate function not viable: no known conversion from ‘void (GLFWwindow , int, int, int, int)’ to ‘GLFWkeyfun’ (aka 'void ()(GLFWwindow *, int, int, unsigned int, int, int)’) for 2nd argument” any ideas?

Hi, this error is from an updated glfw library within the oF core. I added a branch for oF v0.8.3 on the repo.

having an issue with my own addon ofxSecondWindow based on your code.

the second glfw window does not seem to support any alpha channel. No transparency works. @danielalmeida is there something in the initial glfw declaration that could change this?

oops, easy fix. just forgot to enable alpha blending by default in the second window. it’s been fixed now.

Hy Genekogan ! I’m trying your addon that is the simple way to create some windows, but i’m not able to use 3D transform. Is there any tips ?

you can head over to github and try the master branch of OF,
arturo has redesigned openFrameworks core so that it can support multiple windows

go inside examples events and you will find 2 additional ways to implement this.

2 Likes

I’m playing with new GLFW (OF 090), but i’m not able to point to a window…

Exemple : ofSetWindowShape();

How can I select the window that I want resized ? What type of context can I adjust ?

Of course, I can switch the window creation order, but this is not the problem, I would be able to set the window context manually. Any ideas ? (I’m sure it’s possible…)

when you create each window you pass an application to it, any call done from the callback of the corresponding application affects the window it’s configured with, for example with

int main()
{
    ofGLFWWindowSettings settings;
    shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);
    shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);

    shared_ptr<ofApp> mainApp(new ofApp);
    shared_ptr<GuiApp> guiApp(new GuiApp);
    mainApp->gui = guiApp;

    ofRunApp(mainWindow, mainApp);
    ofRunApp(guiWindow, guiApp);
    ofRunMainLoop();
}

Whenever you call ofSetWindowShape(…) from any of ofApp method’s like it’s draw, update, key events… it’ll change the size of the mainWindow. if you call it from any of guiApp methods it’ll change the size of guiWindow.

If you want more flexibility or more explicit syntax you can pass the window, returned by ofCreateWindow(settings) to the app or any other object and call it’s methods instead of the global functions:

int main()
{
    ofGLFWWindowSettings settings;
    shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);
    shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);

    shared_ptr<ofApp> mainApp(new ofApp);
    shared_ptr<GuiApp> guiApp(new GuiApp);
    mainApp->gui = guiApp;
    mainApp->window = mainWindow;
    guiApp->window = guiWindow;

    ofRunApp(mainWindow, mainApp);
    ofRunApp(guiWindow, guiApp);
    ofRunMainLoop();
}

// from the app or any other object:
mainWindow->setWindowShape(w,h);
1 Like

Thx Arturo.

Whenever you call ofSetWindowShape(…) from any of ofApp method’s like it’s draw, update, key events… it’ll change the size of the mainWindow. if you call it from any of guiApp methods it’ll change the size of guiWindow.

In my case, it’s not true, but maybe some of my lib files are out-of-date (i see recent update in the Github tree).

But the second method work well !

I have create a Global class with all ofBaseWindow, so I can call it where I need.

    Global *Gl;
    Gl = new Global();
	
	Gl->adminWindow = ofCreateWindow(settings);
	Gl->mainWindow = ofCreateWindow(settings);

	shared_ptr<adminApp> adminAppWindow(new adminApp(Gl));
	shared_ptr<mainApp> mainAppWindow(new mainApp(Gl));
	
	ofRunApp(Gl->adminWindow , adminAppWindow);
	ofRunApp(Gl->mainWindow, mainAppWindow);

	ofRunMainLoop();

Thank you again !

Is it possible to share a Texture or FBO between 2 windows ?

I tried in both ways, but impossible to share one, in the best case I can share the first frame…

I tried with class storage, global storage, one app class, no result. I can get good size or length of the object but the render is always white or glitch.

you can’t share an fbo but can share a texture. but to share any shareable resource you need to have shared contexts:

    adminWindow = ofCreateWindow(settings);
    settings.shareContextWith = adminWindow;
    mainWindow = ofCreateWindow(settings);
3 Likes

I’m actually having similar issues calling

   ofSetFullscreen(true);

Seems most of the time the last window created receives the events, but not always. Sometimes works as exptected.

(I’m on the very last on Master)

that’s in the event functions right? anyway the last commit should fix it but let me know if it’s still a problem

Yup! That fixed it!
Thanks man! :slight_smile:

i am wondering about the multi window option.
you are calling them separate “apps”. does this mean the os automatically puts each “app” in its own thread?

thanks for helping me understand the advantage of this.

no, both apps run in the same thread one after another right now. we call them apps because the class they inherit from is called ofBaseApp

Thanks for the clarification. it’s much appreciated.