Setup dialog? Exit an app from within itself?

I am trying to make a setup dialog for my app where the user can select the resolution, window mode, various graphics settings and so on, but it seems I need to create a new window to make OF run in fullscreen in a particular resolution - and I’d rather partition the setup dialog and the main app anyway.

As far as I can tell the easiest way would be first to run a setup app in it’s own window and when that exits, pass the settings to a new app that can have it’s own window in whatever setup it needs, but I can’t figure out how to exit an app from within itself without also completely exiting the program.

Here’s how I would do the main() function for that, sans the passing of parameters:

int main()
{
	ofGLWindowSettings glSetupWinSettings;
	glSetupWinSettings.width = 200;
	glSetupWinSettings.height = 400;
	glSetupWinSettings.windowMode = ofWindowMode::OF_WINDOW;
	glSetupWinSettings.setGLVersion(3, 3);
	ofCreateWindow(glSetupWinSettings);

	ofSetupApp* setupApp = new ofSetupApp();
	ofRunApp(setupApp);
	
	if (!setupApp->ShouldQuit())
	{
		ofGLWindowSettings glWindowSettings;
		glWindowSettings.width = 1280;
		glWindowSettings.height = 720;
		glWindowSettings.windowMode = ofWindowMode::OF_GAME_MODE;
		glWindowSettings.setGLVersion(3, 3);
		ofCreateWindow(glWindowSettings);

		ofRunApp(new ofApp());
	}
}

Which seems to work if I remove the conditional and manually close the first window…

Any help would be appreciated :slight_smile:

haven’t tried it but you can probably do:

int main()
{
	ofGLWindowSettings glSetupWinSettings;
	glSetupWinSettings.width = 200;
	glSetupWinSettings.height = 400;
	glSetupWinSettings.windowMode = ofWindowMode::OF_WINDOW;
	glSetupWinSettings.setGLVersion(3, 3);
	auto window = ofCreateWindow(glSetupWinSettings);
	ofSetupApp* setupApp = new ofSetupApp();
        setupApp->window = window;
	ofRunApp(setupApp);
	
	if (!setupApp->ShouldQuit())
	{
		ofGLWindowSettings glWindowSettings;
		glWindowSettings.width = 1280;
		glWindowSettings.height = 720;
		glWindowSettings.windowMode = ofWindowMode::OF_GAME_MODE;
		glWindowSettings.setGLVersion(3, 3);
		ofCreateWindow(glWindowSettings);

		ofRunApp(new ofApp());
	}
}

where window in ofSetupApp is a shared_ptr. to close it from inside the setup app you can call window->close()

Thanks, that works great, except calling close() on window causes an exception, setWindowShouldClose() seems to properly clean up though :slight_smile:

And it doesn’t seem to be necessary to store a pointer to the window, ofGetWindowPtr()->setWindowShouldClose(); works just as well, as far as I can tell.