Exiting glutFullScreen()

c++, glut, opengl

Solution

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.

Problem

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; ```

Original source

Related problems