Detecting if fullscreen

Heyho,
does oF provide an api for detecting if an app is running in fullscreen? Something like ofIsFullscreen(). Or should I go the glfw route?
Does anyone have any pointers?
T

Hey Thomas,

ofAppRunner::ofGetWindowMode() will return an int that you can compare with different window modes, like OF_FULLSCREEN for example: ofAppRunner | openFrameworks.

Hey Tim, thanks for the quick answer. It sounds too easy. Now I remember I tried that a while ago, but I could not get that working.

Could you please quickly test if that works for you?
It does not return the correct value for me. Am I doing something wrong or is this a bug?

#include "ofMain.h"
#include "ofApp.h"
int main()
{
	ofSetupOpenGL(1024, 768, OF_FULLSCREEN);
	ofRunApp(new ofApp());
}
void ofApp::setup(){
    ofLogNotice() << ofGetWindowMode();
    ofLogNotice() << OF_WINDOW;
    ofLogNotice() << OF_FULLSCREEN;
}

[notice ] 0
[notice ] 0
[notice ] 1

i am using of_v0.11.2_osx_release, osx m1

Hey I played around a bit with it. If you need to use the window mode in ofApp::setup(), we may need some more expert help from the forum.

You can use ofGetWindowMode() outside of ofApp::setup(), like this:

void ofApp::keyPressed(int key){
    if(key == 'w') {ofLogNotice("window mode:") << ofGetWindowMode();}
    else if(key == 'f') {ofToggleFullscreen();}
}

But I could not figure out a way to use it in ofApp::setup(), which seems like it runs before a window is created. I’m not totally sure about this though.

If this is the case, you may have to rely on how the window is initially set up in main.cpp, and then use ofGetWindowMode() as needed in the rest of the application. This seems to be the approach taken in the windowExample too.

thanks for giving it a try and confirming.
In my case, I don’t know the game mode set in main. I am working on a library that initialises a gui layer on setup. And I guess I could somehow work around this issue, but it feels like this is a bug in oF. As far as I know setting up glfw, in fullscreen and all these little details, is kinda tricky.
I was wondering if the behaviour is the same on windows machines. @theo, maybe you have some inputs.

Yeah maybe theo and others will post something; windows can be a bit tricky to work with as you say. I can see how you might want to be able to determine the window mode in ofApp::setup() if you’re writing a library that will be used by others.

I can use OF_GAME_MODE in main.cpp, and access the window mode later on; my linux terminal prints a 2 and ofToggleFullscreen() does nothing in that mode. And you can compare the return of ofGetWindowMode() to OF_GAME_MODE, and I’m thinking this should work the same across various platforms:

// in main.cpp
int main( ){
// this method creates a different window than the ofGLFWWindowSettings method
//    ofSetupOpenGL(1024,768,OF_GAME_MODE);

// this creates a full-screen window but is not the same mode as OF_FULSCREEN
    ofGLFWWindowSettings settings;
    settings.setGLVersion(3,3);
    settings.setSize(1024, 768);
    settings.windowMode = OF_GAME_MODE;
    ofCreateWindow(settings);

    ofRunApp(new ofApp());
}

// this prints the notice in the terminal
void ofApp::setup(){
    if(ofGetWindowMode() == OF_GAME_MODE)
    {
        ofLogNotice("OF_GAME_MODE is enabled");        
    }
}

// 'w' prints 2 to the terminal and toggling fullscreen does nothing with OF_GAME_MODE
void ofApp::keyPressed(int key){
    if(key == 'w')
    {
        ofLogNotice("window mode:") << ofGetWindowMode();
        if(ofGetWindowMode() == OF_GAME_MODE)
        {
            // maybe do something interesting with the gui
            ofLogNotice("OF_GAME_MODE is enabled");
        }
    }
    else if(key == 'f') {ofToggleFullscreen();}
}

I’m not sure how many window modes there are, or what oF header defines them; that might be helpful to figure out.

I think the idea of main.cpp and ofApp::setup() is to (together) define an initial state for the application. After these two run, the initial state can change in ofApp::update() and ofApp:draw(). I’m not sure its a bug per se, but maybe more how oF is set up to work as it goes from its initial state to its update/draw cycle.

what about
ofGetWidth() == ofGetScreenWidth() && ofGetHeight() == ofGetScreenHeight()
?

2 Likes

Yeup, that does it! Thomas will be happy I think. ofGetWindowMode() returns 0 in ofApp::setup() when the window mode is either OF_FULLSCREEN or OF_WINDOW. But adding the if statement allows those two modes to be distingushed:

void ofApp::setup(){

    ofLogNotice("window mode:") << ofGetWindowMode();
    if(ofGetWindowMode() == OF_GAME_MODE)
    {
        ofLogNotice("OF_GAME_MODE is enabled");
    }
    else
    {
        if((ofGetWidth() == ofGetScreenWidth()) && ofGetHeight() == ofGetScreenHeight())
        {
            ofLogNotice("fullscreen mode") << ofGetWindowMode();
        }
    }
}

This is a tricky one.

When you do OF_FULLSCREEN in main.cpp the window hasn’t been made fullscreen yet and it actually isn’t until between the first update and the first draw call.

So you don’t get OF_FULLSCREEN as the result of ofGetWindowMode() until it is actually fullscreen on the screen. This is useful for a lot of different reasons, but not for the reason of being able to query if the window is fullscreen in ofApp::setup.

I think the behavior above is consistent across platforms.

Internally there is a targetWindowMode variable which could be exposed with a new function, something like:
ofGetTargetWindowMode();
or
ofAppBaseWindow::getTargetWindowMode();

Though not sure if that would solve your issue?

You could also do some of your gui setup in ofApp::windowResized and only do the setup once ofGetWindowMode() in that function returns OF_FULLSCREEN.

I hope this clarifies things a bit.

Theo

4 Likes

thanks, Tim, Theo, and Roy. That helps to understand what’s going on. I am using Roy’s approach, for now, it seems to work - on osx at least. I might add ofAppBaseWindow::getTargetWindowMode later and send a PR.

2 Likes