mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 14:04:36 +00:00
Removed implicit glfwMakeCurrentContext.
Implicitly making the context current makes sense in a single-window API but less sense in a multi-window one.
This commit is contained in:
parent
2410e2aaf4
commit
2f095cc9e3
@ -589,11 +589,13 @@ int main( void )
|
|||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
reshape(window, width, height);
|
reshape(window, width, height);
|
||||||
|
|
||||||
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
|
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
|
||||||
glfwSwapInterval( 1 );
|
|
||||||
glfwSetTime( 0.0 );
|
glfwSetTime( 0.0 );
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
@ -353,11 +353,13 @@ int main(int argc, char *argv[])
|
|||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
reshape(window, width, height);
|
reshape(window, width, height);
|
||||||
|
|
||||||
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
|
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
|
||||||
glfwSwapInterval( 1 );
|
|
||||||
|
|
||||||
// Parse command-line options
|
// Parse command-line options
|
||||||
init(argc, argv);
|
init(argc, argv);
|
||||||
|
@ -597,10 +597,12 @@ int main(int argc, char** argv)
|
|||||||
free(fragment_shader_src);
|
free(fragment_shader_src);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Register events callback */
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
/* Register events callback */
|
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
if (GL_TRUE != init_opengl())
|
if (GL_TRUE != init_opengl())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: unable to resolve OpenGL function pointers\n");
|
fprintf(stderr, "ERROR: unable to resolve OpenGL function pointers\n");
|
||||||
|
@ -467,12 +467,13 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable vsync
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
windowSizeFun(window, width, height);
|
windowSizeFun(window, width, height);
|
||||||
|
|
||||||
// Enable vsync
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
// Enable sticky keys
|
// Enable sticky keys
|
||||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||||
|
|
||||||
|
@ -30,12 +30,13 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
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
|
// Ensure we can capture the escape key being pressed below
|
||||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||||
|
|
||||||
// Enable vertical sync (on cards that support it)
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
double t = glfwGetTime();
|
double t = glfwGetTime();
|
||||||
|
@ -413,11 +413,12 @@ int main(int argc, char* argv[])
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
window_size_callback(window, width, height);
|
window_size_callback(window, width, height);
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
|
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
|
||||||
|
|
||||||
// Initialize OpenGL
|
// Initialize OpenGL
|
||||||
|
10
src/window.c
10
src/window.c
@ -209,6 +209,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
_GLFWfbconfig fbconfig;
|
_GLFWfbconfig fbconfig;
|
||||||
_GLFWwndconfig wndconfig;
|
_GLFWwndconfig wndconfig;
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
_GLFWwindow* previous;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
@ -254,6 +255,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
if (!_glfwIsValidContextConfig(&wndconfig))
|
if (!_glfwIsValidContextConfig(&wndconfig))
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
// Save the currently current context so it can be restored later
|
||||||
|
previous = glfwGetCurrentContext();
|
||||||
|
|
||||||
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
@ -303,6 +307,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
|
if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +319,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
if (!_glfwRefreshContextParams())
|
if (!_glfwRefreshContextParams())
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,9 +327,13 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
|||||||
if (!_glfwIsValidContext(&wndconfig))
|
if (!_glfwIsValidContext(&wndconfig))
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore the previously current context (or NULL)
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
|
|
||||||
// The GLFW specification states that fullscreen windows have the cursor
|
// The GLFW specification states that fullscreen windows have the cursor
|
||||||
// captured by default
|
// captured by default
|
||||||
if (mode == GLFW_FULLSCREEN)
|
if (mode == GLFW_FULLSCREEN)
|
||||||
|
@ -101,6 +101,8 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
window_size_callback(window, width, height);
|
window_size_callback(window, width, height);
|
||||||
|
|
||||||
|
@ -126,7 +126,9 @@ int main(int argc, char** argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
|
||||||
printf("window size: %ix%i\n", width, height);
|
printf("window size: %ix%i\n", width, height);
|
||||||
|
@ -383,6 +383,7 @@ int main(void)
|
|||||||
|
|
||||||
printf("Window opened\n");
|
printf("Window opened\n");
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
@ -107,6 +107,9 @@ int main(int argc, char** argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
if (!glfwExtensionSupported("GL_ARB_multisample"))
|
if (!glfwExtensionSupported("GL_ARB_multisample"))
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -115,8 +118,6 @@ int main(int argc, char** argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
glGetIntegerv(GL_SAMPLES_ARB, &samples);
|
glGetIntegerv(GL_SAMPLES_ARB, &samples);
|
||||||
if (samples)
|
if (samples)
|
||||||
printf("Context reports FSAA is available with %i samples\n", samples);
|
printf("Context reports FSAA is available with %i samples\n", samples);
|
||||||
|
@ -91,7 +91,9 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(window_focus_callback);
|
glfwSetWindowFocusCallback(window_focus_callback);
|
||||||
|
@ -141,7 +141,9 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
set_gamma(1.f);
|
set_gamma(1.f);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
|
@ -214,6 +214,8 @@ int main(int argc, char** argv)
|
|||||||
if (!window)
|
if (!window)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
// Report GLFW version
|
// Report GLFW version
|
||||||
|
|
||||||
glfwGetVersion(&major, &minor, &revision);
|
glfwGetVersion(&major, &minor, &revision);
|
||||||
|
@ -120,7 +120,9 @@ int main(int argc, char** argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
|
@ -196,6 +196,8 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
|
@ -143,9 +143,11 @@ static void test_modes(void)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetTime(0.0);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
glfwSetTime(0.0);
|
||||||
|
|
||||||
while (glfwGetTime() < 5.0)
|
while (glfwGetTime() < 5.0)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -98,13 +98,15 @@ static GLboolean open_window(void)
|
|||||||
if (!window_handle)
|
if (!window_handle)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window_handle);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
|
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
|
||||||
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
|
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetCursorPosCallback(cursor_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,12 @@ static GLboolean open_window(int width, int height, int mode)
|
|||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window_handle);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
printf("Opening %s mode window took %0.3f seconds\n",
|
printf("Opening %s mode window took %0.3f seconds\n",
|
||||||
get_mode_name(mode),
|
get_mode_name(mode),
|
||||||
|
@ -68,9 +68,11 @@ static GLFWwindow open_window(const char* title, GLFWwindow share)
|
|||||||
if (!window)
|
if (!window)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
set_swap_interval(window, swap_interval);
|
set_swap_interval(window, swap_interval);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
@ -54,6 +54,7 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
@ -64,12 +64,13 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
|
glfwMakeContextCurrent(windows[i]);
|
||||||
|
|
||||||
glClearColor((GLclampf) (i & 1),
|
glClearColor((GLclampf) (i & 1),
|
||||||
(GLclampf) (i >> 1),
|
(GLclampf) (i >> 1),
|
||||||
i ? 0.0 : 1.0,
|
i ? 0.0 : 1.0,
|
||||||
0.0);
|
0.0);
|
||||||
|
|
||||||
|
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
|
Loading…
Reference in New Issue
Block a user