Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

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.

    // Renew calls to glfwOpenWindowHint.
    // (Hints get reset after the call to glfwOpenWindow.)

    // 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;
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);            
share|improve this answer
+1; destroying and recreating the window is also more robust than hoping that the GL context survives the mode transition. Depending on how the OP has his code set up, he should be able to use the same routines for handling the transition as he also uses for regular startup and shutdown (and if it's not set up this way it's a good idea to do so). – MFAH Oct 9 '12 at 19:23
I accepted this answer because I think there is no GLFW functionality to toggling fullscreen mode without loosing the OpenGL context. Reloading all shaders and so on takes some seconds. This would be a nice feature since my game will be nice to play in both windowed and fullscreen mode. For example in Minecraft I often toggled fullscreen depending on if I wanted to do anything else at the same time or not. – danijar Oct 10 '12 at 16:20

I'd suggest looking at the implementation of SFML, which fluently switches between fullscreen and windowed on Windows, Mac and Linux. SFAIK it doesn't use GLFW, but perhaps similar principles apply.

share|improve this answer
I consider switching to SFML. Could you please provide a simple code example for fluently toggling fullscreen mode? – danijar Oct 10 '12 at 16:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.