Thanks Daan, that works. Next problem is how to make seperate windows in object instances, not in main.cpp. This matryoska is very inspiring. Thank you.
I havenāt done this before, but I remembered a recent-ish thread that might be of some help. @dimitre posted some code but I canāt tell if its in main.cpp or not:
Thanks for this. I somehow cannot grasp the problem how to make it workng.
I have ofApp with working videoGrabber (webcam)
I have my custom object, which creates its own window with inherited ofGLFWWindowSettings with sharedContext from main window of ofApp. Object has its own ofPixels storage which I am filling with videoGrabber.getPixels() function in ofApp::update().
I am drawing my objects in for loop in ofApp::draw() and this point seems wrong. All the contents which should be in separate windows is drawn into main ofApp window.
⦠still looking for solution.
The multiWindowOneApp example (and also dimitreās code) uses a listener to draw into the secondary window(s). So could something like that work?
There is also the multiWindowExample, where ofApp has a shared_ptr to another class with its own window (made in main.cpp). It might be interesting to see if this pointer (and window and everything else) could be made in ofApp instead.
Some of the OF examples are very very simple, but contain the basic design pattern for how to do a particular thing in the context of how OF works.
Guys I got it! It took me few hours to fiddle with it but, finally success. @TimChi yes that is true. The examples are simple but showing important design.
thank you all for guiding me.
best
Hey glad you have it working and also thanks for posting some code! You might be able to do this āheadlessā, so that ofApp does not have a window (or anything openGL related), but where the instances of class Sq do have windows. There is the noWindowExample as a guide.
I think if the current app still works after calling ofVideoGrabber::setUseTexture(false), then a headless ofApp would be interesting to try.
Also @zach I LOVE this video in the link! So fun to see you in so many many windows!
I just tried, guided by the noWindowExample, but there are some glitches in the other windows. I think problem could be, that I need to call settings.shareContextWith = mainWindow; to share openGL .
I am not sure, wheter VideoGrabber initialized in ofApp without window could work with noWindow and share properly its contextā¦
Why do you think VideoGrabber::setUseTexture(false) could be interesting? I have read the docs, but I didāt get it
Hey I was thinking that if the video grabber didnāt need a texture, then ofApp could become windowless (and without any openGL context). A call to ofVideoGrabber::setUseTexture() would tell the grabber to just use the pixels. Iām thinking that no openGL context means nothing with an ofTexture can be used.
You could try eliminating settings.shareContextWith = mainWindow; in main.cpp; Iām not sure itās needed and it seems like it may not be doing anything since the main window has been created and no other windows are created in main().
Each instance of class Sq is kind of like its own ofApp in that it derives from ofBaseApp (like ofApp does), has its own window, and a call to ofRunApp() in ofApp::setup(). So each Sq should have its own openGL context anyway. But maybe try it and see how it goes. The design pattern seems similar to the multiWindow example, except that the things that happen in main.cpp (in the example) are happening in ofApp instead.
Also, Iāll bet zach would be more than happy to find some code if it would help.
From my knowledge (which is limited at this time), this code cannnot by eliminated, because there is one global web cam videoGrabber which feeds the ākidsā - instances of other object through ofPixels, so if I understand it correctly GL space sould be shared.
So my question is, whether it is possible to build a of app which has no mainWindow, but web cam videoGrabber is running in it, and when receiving a signal from outside ( e.g. OSC) opens instance of āchildā window with image in it. I donāt know if I am clear enough. I just donāt want main app win. Such an application but with a mainwin works.
Yes you should be able to do this. Here is basic code to get started. Just add anything else as needed to either ofApp or Sq. With a windowless setup, ofApp will only be able to do things that donāt require rendering or openGL stuff (as I understand it).
Also you can use listeners for the instances of Sq; zachās code above has an example of this, as do some of the projects in /examples/windowing/.
main.cpp: (this comes from noWindowExample)
#include "ofMain.h"
#include "ofApp.h"
#include "ofAppNoWindow.h"
int main() {
auto window = make_shared<ofAppNoWindow>();
//to have a normal windowed app comment the line above and uncomment the lines below
//ofGLWindowSettings settings;
//auto window = ofCreateWindow(settings);
ofRunApp(window, make_shared<ofApp>());
ofRunMainLoop();
}
ofApp.h
#pragma once
#include "ofMain.h"
#include "Sq.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void makeSq();
std::vector<std::shared_ptr<Sq>> sqs;
ofVideoGrabber grabber;
};
ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(60);
grabber.setUseTexture(false);
grabber.setDesiredFrameRate(60);
grabber.initGrabber(640, 480);
makeSq();
}
//--------------------------------------------------------------
void ofApp::update(){
grabber.update();
ofPixels& pixels = grabber.getPixels();
for(size_t i{0}; i < sqs.size(); ++i){
sqs.at(i)->setPixels(pixels);
}
if(ofGetFrameNum() % 300 == 0){
// uncomment to make more windows
// makeSq();
}
}
//--------------------------------------------------------------
void ofApp::draw(){
}
//--------------------------------------------------------------
void ofApp::makeSq(){
ofGLWindowSettings settings;
settings.setSize(300, 300);
settings.setPosition(glm::vec2(300,0));
auto window = ofCreateWindow(settings);
auto app = std::make_shared<Sq>();
ofRunApp(window, app);
sqs.push_back(app);
}
OK well adding a video player worked sometimes. Iāll work on it a bit more and see if I can figure it out.
Edit: Iām revising my previous post with some new code that got a bit closer. The windows get created and the pixels from the video grabber make it to a few of them (or so). Maybe they need to come into focus when their pixels are updated and then draw themselves.
Final Edit: I got it working! The code in the previous post should work OK now. The trick was to let each Sq have an ofPixels, and then update its own ofTexture.