Switching between screen modes in runtime using `ofGLFWWindowSettings`

Hi there!

Does anyone know how to switch between screen modes in runtime, when using ofGLFWWindowSettings?

I use this because I have two monitors and display across them both, and I want one window with immediate focus on it.

The modes I need to switch between are below (double fullscreen=across two monitors, single fullscreen=only one monitor and window mode=standard window). Preferably, I should be able to switch between them using keypress in ofApp.cpp.


    ofGLFWWindowSettings settings;
    int mode = 0;

	settings.glVersionMajor = 3;
	settings.glVersionMinor = 2;

	switch (mode)
	{
		case 0: // double fullscreen
			settings.setSize(3840*2, 2160);
			settings.setPosition(glm::vec2(0, 0));
			settings.windowMode = OF_FULLSCREEN;
			settings.multiMonitorFullScreen = true;  
			break;
		case 1: // single fullscreen
			settings.setSize(3840, 2160);
			settings.setPosition(glm::vec2(0, 0));
			settings.windowMode = OF_FULLSCREEN;
			break;
		case 2: // resizable window mode
			settings.setPosition(glm::vec2(0, 0));
			settings.windowMode = OF_WINDOW;
			settings.resizable = true;
			break;
		default:
			break;
	}

    ofCreateWindow(settings);
    ofRunApp(new ofApp()); 

Problem solved!

It was actually quite simple.

In main.cpp:

int main( ){
	ofGLFWWindowSettings settings;
	settings.glVersionMajor = 3;
	settings.glVersionMinor = 2;
	settings.setSize(1280, 720);
	settings.setPosition(glm::vec2(0, 0));
	settings.windowMode = OF_WINDOW;
	settings.multiMonitorFullScreen = true;
	ofCreateWindow(settings);
	ofRunApp(new ofApp());
}

In ofApp.cpp:

void ofApp::keyPressed(int key)
{
    switch (key)
    {
        case 'F':
        case 'f':
            ofToggleFullscreen();
            break;
        default:
            break;
    };
}
2 Likes