diff --git a/examples/boing.c b/examples/boing.c index 9b7e2022..8348df66 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -579,6 +579,7 @@ void DrawGrid( void ) int main( void ) { GLFWwindow window; + int width, height; /* Init GLFW */ if( !glfwInit() ) @@ -587,6 +588,9 @@ int main( void ) exit( EXIT_FAILURE ); } + glfwSetWindowCloseCallback( window_close_callback ); + glfwSetWindowSizeCallback( reshape ); + glfwWindowHint(GLFW_DEPTH_BITS, 16); window = glfwCreateWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL ); @@ -597,8 +601,9 @@ int main( void ) exit( EXIT_FAILURE ); } - glfwSetWindowCloseCallback( window_close_callback ); - glfwSetWindowSizeCallback( reshape ); + glfwGetWindowSize(window, &width, &height); + reshape(window, width, height); + glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); glfwSwapInterval( 1 ); glfwSetTime( 0.0 ); diff --git a/examples/gears.c b/examples/gears.c index 535a574d..ccc06867 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -330,6 +330,7 @@ static void init(int argc, char *argv[]) int main(int argc, char *argv[]) { GLFWwindow window; + int width, height; if( !glfwInit() ) { @@ -337,6 +338,11 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } + // Set callback functions + glfwSetWindowCloseCallback(window_close_callback); + glfwSetWindowSizeCallback( reshape ); + glfwSetKeyCallback( key ); + glfwWindowHint(GLFW_DEPTH_BITS, 16); window = glfwCreateWindow( 300, 300, GLFW_WINDOWED, "Gears", NULL ); @@ -347,17 +353,15 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } + glfwGetWindowSize(window, &width, &height); + reshape(window, width, height); + glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE ); glfwSwapInterval( 1 ); // Parse command-line options init(argc, argv); - // Set callback functions - glfwSetWindowCloseCallback(window_close_callback); - glfwSetWindowSizeCallback( reshape ); - glfwSetKeyCallback( key ); - // Main loop while( running ) { diff --git a/examples/splitview.c b/examples/splitview.c index 0b767b7f..e3f01806 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -456,6 +456,7 @@ static int windowCloseFun(GLFWwindow window) int main(void) { GLFWwindow window; + int width, height; // Initialise GLFW if (!glfwInit()) @@ -464,6 +465,13 @@ int main(void) exit(EXIT_FAILURE); } + // Set callback functions + glfwSetWindowCloseCallback(windowCloseFun); + glfwSetWindowSizeCallback(windowSizeFun); + glfwSetWindowRefreshCallback(windowRefreshFun); + glfwSetCursorPosCallback(cursorPosFun); + glfwSetMouseButtonCallback(mouseButtonFun); + glfwWindowHint(GLFW_DEPTH_BITS, 16); // Open OpenGL window @@ -474,6 +482,9 @@ int main(void) exit(EXIT_FAILURE); } + glfwGetWindowSize(window, &width, &height); + windowSizeFun(window, width, height); + // Enable vsync glfwSwapInterval(1); @@ -483,13 +494,6 @@ int main(void) // Enable mouse cursor (only needed for fullscreen mode) glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); - // Set callback functions - glfwSetWindowCloseCallback(windowCloseFun); - glfwSetWindowSizeCallback(windowSizeFun); - glfwSetWindowRefreshCallback(windowRefreshFun); - glfwSetCursorPosCallback(cursorPosFun); - glfwSetMouseButtonCallback(mouseButtonFun); - // Main loop do { diff --git a/examples/wave.c b/examples/wave.c index ae5447f8..e0c687d6 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -355,7 +355,7 @@ void scroll_callback(GLFWwindow window, double x, double y) // Callback function for window resize events //======================================================================== -void window_resize_callback(GLFWwindow window, int width, int height) +void window_size_callback(GLFWwindow window, int width, int height) { float ratio = 1.f; @@ -391,6 +391,7 @@ int main(int argc, char* argv[]) { GLFWwindow window; double t, dt_total, t_old; + int width, height; if (!glfwInit()) { @@ -398,6 +399,13 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } + glfwSetKeyCallback(key_callback); + glfwSetWindowCloseCallback(window_close_callback); + glfwSetWindowSizeCallback(window_size_callback); + glfwSetMouseButtonCallback(mouse_button_callback); + glfwSetCursorPosCallback(cursor_position_callback); + glfwSetScrollCallback(scroll_callback); + window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL); if (!window) { @@ -405,19 +413,13 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } + glfwGetWindowSize(window, &width, &height); + window_size_callback(window, width, height); + glfwSwapInterval(1); - // Keyboard handler - glfwSetKeyCallback(key_callback); glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE); - // Window resize handler - glfwSetWindowCloseCallback(window_close_callback); - glfwSetWindowSizeCallback(window_resize_callback); - glfwSetMouseButtonCallback(mouse_button_callback); - glfwSetCursorPosCallback(cursor_position_callback); - glfwSetScrollCallback(scroll_callback); - // Initialize OpenGL init_opengl(); diff --git a/src/input.c b/src/input.c index 37da571a..52b3b0fb 100644 --- a/src/input.c +++ b/src/input.c @@ -551,16 +551,6 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun) } _glfwLibrary.cursorPosCallback = cbfun; - - // Call the callback function to let the application know the current - // cursor position - if (cbfun) - { - _GLFWwindow* window; - - for (window = _glfwLibrary.windowListHead; window; window = window->next) - cbfun(window, window->cursorPosX, window->cursorPosY); - } } diff --git a/src/window.c b/src/window.c index 3b0e7a55..f281a256 100644 --- a/src/window.c +++ b/src/window.c @@ -762,16 +762,6 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun) } _glfwLibrary.windowSizeCallback = cbfun; - - // Call the callback function to let the application know the current - // window size - if (cbfun) - { - _GLFWwindow* window; - - for (window = _glfwLibrary.windowListHead; window; window = window->next) - cbfun(window, window->width, window->height); - } } diff --git a/tests/accuracy.c b/tests/accuracy.c index 40894742..079a88b8 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -80,6 +80,7 @@ static void key_callback(GLFWwindow window, int key, int action) int main(void) { GLFWwindow window; + int width, height; if (!glfwInit()) { @@ -87,6 +88,10 @@ int main(void) exit(EXIT_FAILURE); } + glfwSetCursorPosCallback(cursor_position_callback); + glfwSetWindowSizeCallback(window_size_callback); + glfwSetKeyCallback(key_callback); + window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL); if (!window) { @@ -96,11 +101,10 @@ int main(void) exit(EXIT_FAILURE); } - set_swap_interval(window, swap_interval); + glfwGetWindowSize(window, &width, &height); + window_size_callback(window, width, height); - glfwSetCursorPosCallback(cursor_position_callback); - glfwSetWindowSizeCallback(window_size_callback); - glfwSetKeyCallback(key_callback); + set_swap_interval(window, swap_interval); while (glfwGetCurrentContext()) {