Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exiting glutFullScreen()

Tags:

c++

opengl

glut

I don't understand why when I press 'f' it enters into fullscreen but does not exit out of full screen. In the beginning of this method I have set bool fullscreen = false;

Here is the code for my toggle:

case 'f': //toggle screenmode
    if(!fullscreen){
        glutFullScreen();
        fullscreen = true;
    } else if(fullscreen){
        glutReshapeWindow(1200, 900);
        glutPositionWindow(0,0);
        fullscreen = false;
    }
    break;
like image 693
DorkMonstuh Avatar asked Sep 14 '25 20:09

DorkMonstuh


2 Answers

at the top of this method I have set bool fullscreen = false;

Every time you press a key, GLUT will call your keyboard handler. And at the top of your keyboard handler, you create a bool variable named fullscreen and set its value to false. This happens regardless of whether you're in full-screen mode or not. Every time you press a key, this will happen.

If you want to retain a boolean variable that actually tracks whether you're currently fullscreen, then you need to use a global. And you need to not set it at the start of the function. You set it once when you create the window, and you only set it again when you change the fullscreen status of the window.

like image 152
Nicol Bolas Avatar answered Sep 16 '25 11:09

Nicol Bolas


To restore the original window size

... switch the calling order of ReshapeWindow and PositionWindow to

glutPositionWindow(0,0);
glutReshapeWindow(1200, 900);

Otherwise it will go back to windowed mode, but not adapt to the window size you specified!

like image 40
euphrat Avatar answered Sep 16 '25 10:09

euphrat