openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Modernize all examples and templates main.cpp

Open ofTheo opened this issue 4 years ago • 8 comments
trafficstars

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?

ofTheo avatar Mar 25 '21 16:03 ofTheo

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.

themancalledjakob avatar May 02 '21 19:05 themancalledjakob

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

dimitre avatar Jan 10 '22 22:01 dimitre

I would suggest like this as default

	ofRunApp(mainWindow, std::move(mainApp));

because mainApp normally won't be ever used again in this scope

dimitre avatar Feb 20 '22 22:02 dimitre

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.

roymacdonald avatar Feb 21 '22 04:02 roymacdonald

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.

ofTheo avatar Mar 08 '22 22:03 ofTheo

I think that at least the use of new should be take out of all examples

roymacdonald avatar Mar 09 '22 02:03 roymacdonald

@roymacdonald yeah totally! 🙂

ofTheo avatar Mar 09 '22 04:03 ofTheo

Any suggestions on this one @ofZach ?

dimitre avatar May 20 '22 21:05 dimitre