From 2972cdfeb1e7e5b77cb889aaf787896885917a09 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 3 Aug 2012 16:20:52 +0200 Subject: [PATCH] Removed glfwIsWindow. --- examples/boing.c | 17 +++++++++++++++-- examples/gears.c | 15 +++++++++------ examples/splitview.c | 21 +++++++++++++++++++-- examples/triangle.c | 16 ++++++++++++++-- examples/wave.c | 15 ++++++++++++--- include/GL/glfw3.h | 1 - readme.html | 1 - src/window.c | 28 ---------------------------- tests/accuracy.c | 2 +- tests/clipboard.c | 2 +- tests/events.c | 2 +- tests/fsaa.c | 2 +- tests/fsfocus.c | 3 ++- tests/gamma.c | 2 +- tests/iconify.c | 2 +- tests/joysticks.c | 3 +-- tests/peter.c | 2 +- tests/sharing.c | 22 ++++++++++++++++++++-- tests/tearing.c | 2 +- tests/title.c | 2 +- tests/windows.c | 17 ++++++++++------- 21 files changed, 111 insertions(+), 66 deletions(-) diff --git a/examples/boing.c b/examples/boing.c index 49d602ca..d3b34172 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -43,6 +43,7 @@ void init( void ); void display( void ); void reshape( GLFWwindow window, int w, int h ); +int window_close_callback(GLFWwindow window); void DrawBoingBall( void ); void BounceBall( double dt ); void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi ); @@ -89,6 +90,7 @@ DRAW_BALL_ENUM drawBallHow; double t; double t_old = 0.f; double dt; +static GLboolean running = GL_TRUE; /* Random number generator */ #ifndef RAND_MAX @@ -245,6 +247,16 @@ void reshape( GLFWwindow window, int w, int h ) } +/***************************************************************************** + * Window close callback + *****************************************************************************/ +int window_close_callback(GLFWwindow window) +{ + running = GL_FALSE; + return GL_TRUE; +} + + /***************************************************************************** * Draw the Boing ball. * @@ -567,7 +579,6 @@ void DrawGrid( void ) int main( void ) { - int running; GLFWwindow window; /* Init GLFW */ @@ -587,6 +598,7 @@ int main( void ) exit( EXIT_FAILURE ); } + glfwSetWindowCloseCallback( window_close_callback ); glfwSetWindowSizeCallback( reshape ); glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); glfwSwapInterval( 1 ); @@ -610,7 +622,8 @@ int main( void ) glfwPollEvents(); /* Check if we are still running */ - running = glfwIsWindow(window) && !glfwGetKey( window, GLFW_KEY_ESCAPE ); + if (glfwGetKey( window, GLFW_KEY_ESCAPE )) + running = GL_FALSE; } while( running ); diff --git a/examples/gears.c b/examples/gears.c index 53d601f3..4ce68ab6 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -267,6 +267,14 @@ void reshape( GLFWwindow window, int width, int height ) } +/* close callback */ +int window_close_callback(GLFWwindow window) +{ + running = 0; + return GL_TRUE; +} + + /* program & OpenGL initialization */ static void init(int argc, char *argv[]) { @@ -346,6 +354,7 @@ int main(int argc, char *argv[]) init(argc, argv); // Set callback functions + glfwSetWindowCloseCallback(window_close_callback); glfwSetWindowSizeCallback( reshape ); glfwSetKeyCallback( key ); @@ -361,12 +370,6 @@ int main(int argc, char *argv[]) // Swap buffers glfwSwapBuffers(); glfwPollEvents(); - - // Was the window closed? - if( !glfwIsWindow( window ) ) - { - running = 0; - } } // Terminate GLFW diff --git a/examples/splitview.c b/examples/splitview.c index c584f9af..d9595717 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -42,6 +42,9 @@ static int rot_x = 0, rot_y = 0, rot_z = 0; // Do redraw? static int do_redraw = 1; +// Keep running? +static GLboolean running = GL_TRUE; + //======================================================================== // Draw a solid torus (use a display list for the model) @@ -435,6 +438,17 @@ static void mouseButtonFun(GLFWwindow window, int button, int action) } +//======================================================================== +// Window close callback function +//======================================================================== + +static int windowCloseFun(GLFWwindow window) +{ + running = GL_FALSE; + return GL_TRUE; +} + + //======================================================================== // main //======================================================================== @@ -470,6 +484,7 @@ int main(void) glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); // Set callback functions + glfwSetWindowCloseCallback(windowCloseFun); glfwSetWindowSizeCallback(windowSizeFun); glfwSetWindowRefreshCallback(windowRefreshFun); glfwSetCursorPosCallback(cursorPosFun); @@ -493,9 +508,11 @@ int main(void) // Wait for new events glfwWaitEvents(); + if (glfwGetKey(window, GLFW_KEY_ESCAPE)) + running = GL_FALSE; + } // Check if the ESC key was pressed or the window was closed - while (glfwIsWindow(window) && - glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS); + while (running); // Close OpenGL window and terminate GLFW glfwTerminate(); diff --git a/examples/triangle.c b/examples/triangle.c index ee340496..bf26a94e 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -10,6 +10,14 @@ #define GLFW_INCLUDE_GLU #include +static GLboolean running = GL_TRUE; + +static int window_close_callback(GLFWwindow window) +{ + running = GL_FALSE; + return GL_TRUE; +} + int main(void) { int width, height, x; @@ -36,6 +44,8 @@ int main(void) // Enable vertical sync (on cards that support it) glfwSwapInterval(1); + glfwSetWindowCloseCallback(window_close_callback); + do { double t = glfwGetTime(); @@ -82,9 +92,11 @@ int main(void) glfwSwapBuffers(); glfwPollEvents(); + if (glfwGetKey(window, GLFW_KEY_ESCAPE)) + running = GL_FALSE; + } // Check if the ESC key was pressed or the window was closed - while (glfwIsWindow(window) && - glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS); + while (running); // Close OpenGL window and terminate GLFW glfwTerminate(); diff --git a/examples/wave.c b/examples/wave.c index 54574839..00e74039 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -372,6 +372,17 @@ void window_resize_callback(GLFWwindow window, int width, int height) } +//======================================================================== +// Callback function for window close events +//======================================================================== + +static int window_close_callback(GLFWwindow window) +{ + running = GL_FALSE; + return GL_TRUE; +} + + //======================================================================== // main //======================================================================== @@ -401,6 +412,7 @@ int main(int argc, char* argv[]) 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); @@ -441,9 +453,6 @@ int main(int argc, char* argv[]) draw_scene(); glfwPollEvents(); - - // Still running? - running = running && glfwIsWindow(window); } exit(EXIT_SUCCESS); diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 7a47f86e..f1d9f5cc 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -529,7 +529,6 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp); /* Window handling */ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title, GLFWwindow share); GLFWAPI void glfwOpenWindowHint(int target, int hint); -GLFWAPI int glfwIsWindow(GLFWwindow window); GLFWAPI void glfwCloseWindow(GLFWwindow window); GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title); GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height); diff --git a/readme.html b/readme.html index 12f73f3c..9627ecb6 100644 --- a/readme.html +++ b/readme.html @@ -268,7 +268,6 @@ version of GLFW.

v3.0