Removed implicit glfwMakeCurrentContext.

Implicitly making the context current makes sense in a
single-window API but less sense in a multi-window one.
diff --git a/examples/boing.c b/examples/boing.c
index c0d3f0e..3cc0973 100644
--- a/examples/boing.c
+++ b/examples/boing.c
@@ -589,11 +589,13 @@
        exit( EXIT_FAILURE );
    }
 
+   glfwMakeContextCurrent(window);
+   glfwSwapInterval( 1 );
+
    glfwGetWindowSize(window, &width, &height);
    reshape(window, width, height);
 
    glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
-   glfwSwapInterval( 1 );
    glfwSetTime( 0.0 );
 
    init();
diff --git a/examples/gears.c b/examples/gears.c
index ccc0686..cd3cdbb 100644
--- a/examples/gears.c
+++ b/examples/gears.c
@@ -353,11 +353,13 @@
         exit( EXIT_FAILURE );
     }
 
+    glfwMakeContextCurrent(window);
+    glfwSwapInterval( 1 );
+
     glfwGetWindowSize(window, &width, &height);
     reshape(window, width, height);
 
     glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
-    glfwSwapInterval( 1 );
 
     // Parse command-line options
     init(argc, argv);
diff --git a/examples/heightmap.c b/examples/heightmap.c
index ce894f9..fce8b8d 100644
--- a/examples/heightmap.c
+++ b/examples/heightmap.c
@@ -597,10 +597,12 @@
         free(fragment_shader_src);
         exit(EXIT_FAILURE);
     }
+
+    /* Register events callback */
     glfwSetWindowCloseCallback(window_close_callback);
     glfwSetKeyCallback(key_callback);
-    /* Register events callback */
 
+    glfwMakeContextCurrent(window);
     if (GL_TRUE != init_opengl())
     {
         fprintf(stderr, "ERROR: unable to resolve OpenGL function pointers\n");
diff --git a/examples/splitview.c b/examples/splitview.c
index 2f53f45..c602d0c 100644
--- a/examples/splitview.c
+++ b/examples/splitview.c
@@ -467,12 +467,13 @@
         exit(EXIT_FAILURE);
     }
 
+    // Enable vsync
+    glfwMakeContextCurrent(window);
+    glfwSwapInterval(1);
+
     glfwGetWindowSize(window, &width, &height);
     windowSizeFun(window, width, height);
 
-    // Enable vsync
-    glfwSwapInterval(1);
-
     // Enable sticky keys
     glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
 
diff --git a/examples/triangle.c b/examples/triangle.c
index 9ebfbca..615483a 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -30,12 +30,13 @@
         exit(EXIT_FAILURE);
     }
 
+    // Enable vertical sync (on cards that support it)
+    glfwMakeContextCurrent(window);
+    glfwSwapInterval(1);
+
     // Ensure we can capture the escape key being pressed below
     glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
 
-    // Enable vertical sync (on cards that support it)
-    glfwSwapInterval(1);
-
     for (;;)
     {
         double t = glfwGetTime();
diff --git a/examples/wave.c b/examples/wave.c
index e0c687d..668d54b 100644
--- a/examples/wave.c
+++ b/examples/wave.c
@@ -413,11 +413,12 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
+    glfwSwapInterval(1);
+
     glfwGetWindowSize(window, &width, &height);
     window_size_callback(window, width, height);
 
-    glfwSwapInterval(1);
-
     glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
 
     // Initialize OpenGL
diff --git a/src/window.c b/src/window.c
index 81b525b..df59275 100644
--- a/src/window.c
+++ b/src/window.c
@@ -209,6 +209,7 @@
     _GLFWfbconfig fbconfig;
     _GLFWwndconfig wndconfig;
     _GLFWwindow* window;
+    _GLFWwindow* previous;
 
     if (!_glfwInitialized)
     {
@@ -254,6 +255,9 @@
     if (!_glfwIsValidContextConfig(&wndconfig))
         return GL_FALSE;
 
+    // Save the currently current context so it can be restored later
+    previous = glfwGetCurrentContext();
+
     if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
     {
         _glfwSetError(GLFW_INVALID_ENUM,
@@ -303,6 +307,7 @@
     if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
     {
         glfwDestroyWindow(window);
+        glfwMakeContextCurrent(previous);
         return GL_FALSE;
     }
 
@@ -314,6 +319,7 @@
     if (!_glfwRefreshContextParams())
     {
         glfwDestroyWindow(window);
+        glfwMakeContextCurrent(previous);
         return GL_FALSE;
     }
 
@@ -321,9 +327,13 @@
     if (!_glfwIsValidContext(&wndconfig))
     {
         glfwDestroyWindow(window);
+        glfwMakeContextCurrent(previous);
         return GL_FALSE;
     }
 
+    // Restore the previously current context (or NULL)
+    glfwMakeContextCurrent(previous);
+
     // The GLFW specification states that fullscreen windows have the cursor
     // captured by default
     if (mode == GLFW_FULLSCREEN)
diff --git a/tests/accuracy.c b/tests/accuracy.c
index acf9be2..30235a5 100644
--- a/tests/accuracy.c
+++ b/tests/accuracy.c
@@ -101,6 +101,8 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
+
     glfwGetWindowSize(window, &width, &height);
     window_size_callback(window, width, height);
 
diff --git a/tests/clipboard.c b/tests/clipboard.c
index 654de5f..fcd1c30 100644
--- a/tests/clipboard.c
+++ b/tests/clipboard.c
@@ -126,7 +126,9 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
+
     glfwSetKeyCallback(key_callback);
     glfwSetWindowSizeCallback(size_callback);
 
diff --git a/tests/defaults.c b/tests/defaults.c
index fc7b96c..5e3f389 100644
--- a/tests/defaults.c
+++ b/tests/defaults.c
@@ -95,6 +95,7 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
     glfwGetWindowSize(window, &width, &height);
 
     printf("window size: %ix%i\n", width, height);
diff --git a/tests/events.c b/tests/events.c
index 20051a2..f82b8fc 100644
--- a/tests/events.c
+++ b/tests/events.c
@@ -383,6 +383,7 @@
 
     printf("Window opened\n");
 
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
 
     glfwGetWindowSize(window, &width, &height);
diff --git a/tests/fsaa.c b/tests/fsaa.c
index 2a9ccfb..8fc8b60 100644
--- a/tests/fsaa.c
+++ b/tests/fsaa.c
@@ -107,6 +107,9 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
+    glfwSwapInterval(1);
+
     if (!glfwExtensionSupported("GL_ARB_multisample"))
     {
         glfwTerminate();
@@ -115,8 +118,6 @@
         exit(EXIT_FAILURE);
     }
 
-    glfwSwapInterval(1);
-
     glGetIntegerv(GL_SAMPLES_ARB, &samples);
     if (samples)
         printf("Context reports FSAA is available with %i samples\n", samples);
diff --git a/tests/fsfocus.c b/tests/fsfocus.c
index e718a31..1c46d7a 100644
--- a/tests/fsfocus.c
+++ b/tests/fsfocus.c
@@ -91,7 +91,9 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
+
     glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
 
     glfwSetWindowFocusCallback(window_focus_callback);
diff --git a/tests/gamma.c b/tests/gamma.c
index b2f1f2b..7d93ed0 100644
--- a/tests/gamma.c
+++ b/tests/gamma.c
@@ -141,7 +141,9 @@
 
     set_gamma(1.f);
 
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
+
     glfwSetKeyCallback(key_callback);
     glfwSetWindowSizeCallback(size_callback);
 
diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c
index 4990ff0..90fd329 100644
--- a/tests/glfwinfo.c
+++ b/tests/glfwinfo.c
@@ -214,6 +214,8 @@
     if (!window)
         exit(EXIT_FAILURE);
 
+    glfwMakeContextCurrent(window);
+
     // Report GLFW version
 
     glfwGetVersion(&major, &minor, &revision);
diff --git a/tests/iconify.c b/tests/iconify.c
index 221d558..d1a505b 100644
--- a/tests/iconify.c
+++ b/tests/iconify.c
@@ -120,7 +120,9 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
+
     glfwSetKeyCallback(key_callback);
     glfwSetWindowSizeCallback(size_callback);
 
diff --git a/tests/joysticks.c b/tests/joysticks.c
index 374ec82..488f98a 100644
--- a/tests/joysticks.c
+++ b/tests/joysticks.c
@@ -196,6 +196,8 @@
     }
 
     glfwSetWindowSizeCallback(window_size_callback);
+
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
 
     while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
diff --git a/tests/modes.c b/tests/modes.c
index 2293a39..660f89d 100644
--- a/tests/modes.c
+++ b/tests/modes.c
@@ -143,9 +143,11 @@
             continue;
         }
 
-        glfwSetTime(0.0);
+        glfwMakeContextCurrent(window);
         glfwSwapInterval(1);
 
+        glfwSetTime(0.0);
+
         while (glfwGetTime() < 5.0)
         {
             glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/peter.c b/tests/peter.c
index be772e9..ae6e4b7 100644
--- a/tests/peter.c
+++ b/tests/peter.c
@@ -98,13 +98,15 @@
     if (!window_handle)
         return GL_FALSE;
 
+    glfwMakeContextCurrent(window_handle);
+    glfwSwapInterval(1);
+
     glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
     printf("Cursor position: %i %i\n", cursor_x, cursor_y);
 
     glfwSetWindowSizeCallback(window_size_callback);
     glfwSetCursorPosCallback(cursor_position_callback);
     glfwSetKeyCallback(key_callback);
-    glfwSwapInterval(1);
 
     return GL_TRUE;
 }
diff --git a/tests/reopen.c b/tests/reopen.c
index 545ba28..5d13718 100644
--- a/tests/reopen.c
+++ b/tests/reopen.c
@@ -99,10 +99,12 @@
         return GL_FALSE;
     }
 
+    glfwMakeContextCurrent(window_handle);
+    glfwSwapInterval(1);
+
     glfwSetWindowSizeCallback(window_size_callback);
     glfwSetWindowCloseCallback(window_close_callback);
     glfwSetKeyCallback(key_callback);
-    glfwSwapInterval(1);
 
     printf("Opening %s mode window took %0.3f seconds\n",
            get_mode_name(mode),
diff --git a/tests/sharing.c b/tests/sharing.c
index 8031a9b..95f2134 100644
--- a/tests/sharing.c
+++ b/tests/sharing.c
@@ -68,9 +68,11 @@
     if (!window)
         return NULL;
 
+    glfwMakeContextCurrent(window);
+    glfwSwapInterval(1);
+
     glfwSetWindowCloseCallback(window_close_callback);
     glfwSetKeyCallback(key_callback);
-    glfwSwapInterval(1);
 
     return window;
 }
diff --git a/tests/tearing.c b/tests/tearing.c
index 51e110a..c2349c8 100644
--- a/tests/tearing.c
+++ b/tests/tearing.c
@@ -81,6 +81,7 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
     set_swap_interval(window, swap_interval);
 
     glfwSetWindowSizeCallback(window_size_callback);
diff --git a/tests/title.c b/tests/title.c
index 1370b33..c753903 100644
--- a/tests/title.c
+++ b/tests/title.c
@@ -54,6 +54,7 @@
         exit(EXIT_FAILURE);
     }
 
+    glfwMakeContextCurrent(window);
     glfwSwapInterval(1);
 
     glfwSetWindowSizeCallback(window_size_callback);
diff --git a/tests/windows.c b/tests/windows.c
index ce0609a..7b1a529 100644
--- a/tests/windows.c
+++ b/tests/windows.c
@@ -64,12 +64,13 @@
             exit(EXIT_FAILURE);
         }
 
-        glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
-
+        glfwMakeContextCurrent(windows[i]);
         glClearColor((GLclampf) (i & 1),
                      (GLclampf) (i >> 1),
                      i ? 0.0 : 1.0,
                      0.0);
+
+        glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
     }
 
     while (running)