Using the library GLFW, I can create a fullscreen window using this line of code.
glfwOpenWindow(Width, Height, 8, 8, 8, 8, 24, 0, GLFW_FULLSCREEN);
The line for creating a standard window looks like this.
glfwOpenWindow(Width, Height, 8, 8, 8, 8, 24, 0, GLFW_WINDOW);
What I want to do is letting the user switch between standard window and fullscreen by a keypress, let's say F11
.
It there a common practice of toggling fullscreen mode? What do I have to consider?
Answer
I'm not sure about common practices, but lacking a glfwToggleFullscreen
, this seems one way to toggle fullscreen mode:
// On input handling, check if F11 is down.
if ( glfwGetKey( GLFW_KEY_F11 ) ) {
// Toggle fullscreen flag.
fullscreen = !fullscreen;
// Close the current window.
glfwCloseWindow();
// Renew calls to glfwOpenWindowHint.
// (Hints get reset after the call to glfwOpenWindow.)
myGLFWOpenWindowHints();
// Create the new window.
glfwOpenWindow(Width, Height, 8, 8, 8, 8, 24, 0,
fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW);
}
Another method, this time for fullscreen windowed mode:
// Create your window in windowed mode.
glfwOpenWindow(originalWidth, originalHeight, 8, 8, 8, 8, 24, 0, GLFW_WINDOW);
glfwSetWindowPos(originalPosX, originalPosY);
// Get the desktop resolution.
GLFWvidmode desktopMode;
glfwGetDesktopMode(&desktopMode);
desktopHeight = desktopMode.Height;
desktopWidth = desktopMode.Width;
// --8<--
// On input handling, check if F11 is down.
if ( glfwGetKey( GLFW_KEY_F11 ) ) {
// Toggle fullscreen flag.
fullscreen = !fullscreen;
if ( fullscreen ) {
// Set window size for "fullscreen windowed" mode to the desktop resolution.
glfwSetWindowSize(desktopWidth, desktopHeight);
// Move window to the upper left corner.
glfwSetWindowPos(0, 0);
} else {
// Use start-up values for "windowed" mode.
glfwSetWindowSize(originalWidth, originalHeight);
glfwSetWindowPos(originalPosX, originalPosY);
}
}
No comments:
Post a Comment