title: Switching Between windowed and full screen in OpenGL/GLFW 3.2
body: <p>I am in the process of learning OpenGL on Linux but I can't get mode switching working (windowed to full screen and back).</p>
  
  <p>The window appears to be going into full screen but but not looking correct.  To switch modes a new window is being created and old one destroyed.</p>
  
  <pre><code>void OpenGLWindow::FullScreen(bool fullScreen, int width, int height)
  {
      GLFWwindow *oldHandle = m_window;
  
      m_fullscreen = fullScreen;
      m_width = width;
      m_height = height;
  
      m_window = glfwCreateWindow(width, height, m_caption.c_str(),
          fullScreen ? m_monitor : NULL, m_window);
  
      if (m_window == NULL)
      {
          glfwTerminate();
          throw std::runtime_error("Failed to recreate window.");
      }
  
      glfwDestroyWindow(oldHandle);
  
      m_camera-&gt;Invalidate();
  
      // Use entire window for rendering.
      glViewport(0, 0, width, height);
  
      glfwMakeContextCurrent(m_window);
      glfwSwapInterval(1);
  
      if (m_keyboardHandler) SetKeyboardHandler(m_keyboardHandler);
  }
  </code></pre>
  
  <p><strong>Initial Window</strong>
  <a href="https://i.stack.imgur.com/ybN3y.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ybN3y.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Full Screen (incorrect)</strong>
  <a href="https://i.stack.imgur.com/huNO1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/huNO1.png" alt="enter image description here"></a></p>
  
  <p><strong>Return to Windowed</strong>
  <a href="https://i.stack.imgur.com/ylJVs.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ylJVs.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Updates to Question</strong></p>
  
  <p>I have updated the code to use your code and getting the same issue.  On your suggestion I am now updating the camera, but again no avail :(</p>
  
  <pre><code>void OpenGLCamera::Invalidate()
  {
      RecalculateProjection(m_perspProjInfo-&gt;Width(), m_perspProjInfo-&gt;Height());
      m_recalculateViewMatrix = true;
      m_recalculatePerspectiveMatrix = true;
      m_recalculateProjectionMatrix = true;
  }
  
  void OpenGLCamera::RecalculateProjection(int width, int height)
  {
      float aspectRatio = float(width) / height;
      float frustumYScale = cotangent(degreesToRadians(
          m_perspProjInfo-&gt;FieldOfView() / 2));
  
      float frustumXScale = frustumYScale;
  
      if (width &gt; height) 
      {
          // Shrink the x scale in eye-coordinate space, so that when geometry is
          // projected to ndc-space, it is widened out to become square.
          m_projectionMatrix[0][0] = frustumXScale / aspectRatio;
          m_projectionMatrix[1][1] = frustumYScale;
      }
      else {
          // Shrink the y scale in eye-coordinate space, so that when geometry is
          // projected to ndc-space, it is widened out to become square.
          m_projectionMatrix[0][0] = frustumXScale;
          m_projectionMatrix[1][1] = frustumYScale * aspectRatio;
      }
  }
  </code></pre>
  
  <p>Rabbid : When I resize:</p>
  
  <p><a href="https://i.stack.imgur.com/se5CB.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/se5CB.jpg" alt="enter image description here"></a></p>
  
  <p>Rabbid : When I go to full screen:
  <a href="https://i.stack.imgur.com/Aaaio.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Aaaio.jpg" alt="enter image description here"></a></p>