openFrameworks
openFrameworks copied to clipboard
Modernize all examples and templates main.cpp
Right now most of the examples in OF show the old way of making a window and starting an app.
eg:
//========================================================================
int main( ){
ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new ofApp());
}
For 0.12.0 should update the examples to use the newer calls and make sure the older methods are marked deprecated.
eg
//========================================================================
int main( ){
ofWindowSettings settings;
settings.setSize(1024, 768);
settings.windowMode = OF_WINDOW;
auto mainWindow = ofCreateWindow(settings);
auto mainApp = make_shared<ofApp>();
ofRunApp(mainWindow, mainApp);
ofRunMainLoop();
}
The above hides the ofGLFWWindowSettings features but also the dependency. Not sure if we should include some commented out code above to show how to use the more feature rich ofGLFWWindowSettings options?
The above hides the ofGLFWWindowSettings features but also the dependency. Not sure if we should include some commented out code above to show how to use the more feature rich ofGLFWWindowSettings options?
why not just add an example like examples/windowing/advancedWindowExample and show off the features?
People interested in windowing features would check that out, and it would keep the other examples cleaner.
I too like the minimal way of creating an app for basic examples. any reason it will be deprecated? will be something similar available?
int main( ){
ofSetupOpenGL(1024,768, OF_WINDOW);
ofRunApp( new ofApp());
}
But if you decide to update all examples to explicit settings initialization count on me to write a Python parser to replace them all
I would suggest like this as default
ofRunApp(mainWindow, std::move(mainApp));
because mainApp normally won't be ever used again in this scope
what about having a ofRunApp to be a templated function which gets the app class as template and it initializes it, thus hiding a lot from regular users, while leaving as an optional way to init the one that currently is, just in case.
something like
template<typename AppClass>
void ofRunApp(const ofWindowSettings& windowSettings){
auto mainWindow = ofCreateWindow(windowSettings);
auto mainApp = make_shared<AppClass>();
ofRunApp(mainWindow, mainApp);
ofRunMainLoop();
}
which in main.cpp should look something like
//========================================================================
int main( ){
ofWindowSettings settings;
settings.setSize(1024, 768);
settings.windowMode = OF_WINDOW;
ofRunApp<ofApp>(settings);
}
To me it looks a lot more elegant.
Definitely open to clearer approaches. I honestly have had to look up the new way from the examples multiple times and often miss something.
Not sure about the template one though - seems a bit much of a departure of the user facing stuff we currently have. 🙂
Btw I think the reason we currently have ofRunMainLoop(); after ofRunApp(mainWindow, mainApp); is so you can have multiple apps run by the main loop.
eg from the multi window example:
ofRunApp(guiWindow, guiApp);
ofRunApp(mainWindow, mainApp);
ofRunMainLoop();
ofRunMainLoop() is the line I often forget though.
I think that at least the use of new should be take out of all examples
@roymacdonald yeah totally! 🙂
Any suggestions on this one @ofZach ?