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
- Added
GLFWwindow
window handle type and updated window-related functions and callbacks to take a window handle
- - Added
glfwIsWindow
function for verifying that a given window handle is (still) valid
- Added
glfwMakeContextCurrent
function for making the context of the specified window current
- Added
glfwGetError
and glfwErrorString
error reporting functions and a number of error tokens
- Added
glfwSetErrorCallback
function and GLFWerrorfun
type for receiving more specific and/or nested errors
diff --git a/src/window.c b/src/window.c
index 27237329..fb69396d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -350,34 +350,6 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
}
-//========================================================================
-// Returns GL_TRUE if the specified window handle is an actual window
-//========================================================================
-
-GLFWAPI int glfwIsWindow(GLFWwindow handle)
-{
- _GLFWwindow* entry;
- _GLFWwindow* window = (_GLFWwindow*) handle;
-
- if (!_glfwInitialized)
- {
- _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
- return GL_FALSE;
- }
-
- if (window == NULL)
- return GL_FALSE;
-
- for (entry = _glfwLibrary.windowListHead; entry; entry = entry->next)
- {
- if (entry == window)
- return GL_TRUE;
- }
-
- return GL_FALSE;
-}
-
-
//========================================================================
// Set hints for opening the window
//========================================================================
diff --git a/tests/accuracy.c b/tests/accuracy.c
index cfb70271..614f270f 100644
--- a/tests/accuracy.c
+++ b/tests/accuracy.c
@@ -79,7 +79,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
- while (glfwIsWindow(window))
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/clipboard.c b/tests/clipboard.c
index 3b732290..05724f25 100644
--- a/tests/clipboard.c
+++ b/tests/clipboard.c
@@ -136,7 +136,7 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0);
- while (glfwIsWindow(window))
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/events.c b/tests/events.c
index 8ab54266..7528e96f 100644
--- a/tests/events.c
+++ b/tests/events.c
@@ -385,7 +385,7 @@ int main(void)
printf("Main loop starting\n");
- while (glfwIsWindow(window) == GL_TRUE)
+ while (glfwGetCurrentContext())
glfwWaitEvents();
glfwTerminate();
diff --git a/tests/fsaa.c b/tests/fsaa.c
index 9c45ddcc..4d22c4a6 100644
--- a/tests/fsaa.c
+++ b/tests/fsaa.c
@@ -127,7 +127,7 @@ int main(int argc, char** argv)
gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
glMatrixMode(GL_MODELVIEW);
- while (glfwIsWindow(window))
+ while (glfwGetCurrentContext())
{
GLfloat time = (GLfloat) glfwGetTime();
diff --git a/tests/fsfocus.c b/tests/fsfocus.c
index 951409a6..b4bc7cb4 100644
--- a/tests/fsfocus.c
+++ b/tests/fsfocus.c
@@ -68,6 +68,7 @@ static void window_key_callback(GLFWwindow window, int key, int action)
static int window_close_callback(GLFWwindow window)
{
printf("%0.3f: User closed window\n", glfwGetTime());
+ running = GL_FALSE;
return GL_TRUE;
}
@@ -97,7 +98,7 @@ int main(void)
glfwSetKeyCallback(window_key_callback);
glfwSetWindowCloseCallback(window_close_callback);
- while (running && glfwIsWindow(window) == GL_TRUE)
+ while (running)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
diff --git a/tests/gamma.c b/tests/gamma.c
index b8ec6c45..22b6acd5 100644
--- a/tests/gamma.c
+++ b/tests/gamma.c
@@ -151,7 +151,7 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0);
- while (glfwIsWindow(window))
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/iconify.c b/tests/iconify.c
index dbc4d9cf..f9333f47 100644
--- a/tests/iconify.c
+++ b/tests/iconify.c
@@ -126,7 +126,7 @@ int main(int argc, char** argv)
glEnable(GL_SCISSOR_TEST);
- while (glfwIsWindow(window))
+ while (glfwGetCurrentContext())
{
int width, height;
diff --git a/tests/joysticks.c b/tests/joysticks.c
index 2f208d2b..3abd5fdd 100644
--- a/tests/joysticks.c
+++ b/tests/joysticks.c
@@ -44,7 +44,6 @@ typedef struct Joystick
} Joystick;
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
-
static int joystick_count = 0;
static void window_size_callback(GLFWwindow window, int width, int height)
@@ -199,7 +198,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
- while (glfwIsWindow(window))
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/peter.c b/tests/peter.c
index b9f21f22..e814caf6 100644
--- a/tests/peter.c
+++ b/tests/peter.c
@@ -127,7 +127,7 @@ int main(void)
glClearColor(0.f, 0.f, 0.f, 0.f);
- while (glfwIsWindow(window_handle))
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/sharing.c b/tests/sharing.c
index 6f1df980..ed5ae024 100644
--- a/tests/sharing.c
+++ b/tests/sharing.c
@@ -36,12 +36,30 @@
#define WIDTH 400
#define HEIGHT 400
+static GLFWwindow windows[2];
+
static void key_callback(GLFWwindow window, int key, int action)
{
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
glfwCloseWindow(window);
}
+static int window_close_callback(GLFWwindow window)
+{
+ int i;
+
+ for (i = 0; i < 2; i++)
+ {
+ if (windows[i] == window)
+ {
+ windows[i] = NULL;
+ break;
+ }
+ }
+
+ return GL_TRUE;
+}
+
static GLFWwindow open_window(const char* title, GLFWwindow share)
{
GLFWwindow window;
@@ -50,6 +68,7 @@ static GLFWwindow open_window(const char* title, GLFWwindow share)
if (!window)
return NULL;
+ glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
glfwSwapInterval(1);
@@ -112,7 +131,6 @@ static void draw_quad(GLuint texture)
int main(int argc, char** argv)
{
- GLFWwindow windows[2];
GLuint texture;
int x, y;
@@ -150,7 +168,7 @@ int main(int argc, char** argv)
glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
- while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1]))
+ while (windows[0] && windows[1])
{
glfwMakeContextCurrent(windows[0]);
draw_quad(texture);
diff --git a/tests/tearing.c b/tests/tearing.c
index 1eab454e..64819c17 100644
--- a/tests/tearing.c
+++ b/tests/tearing.c
@@ -87,7 +87,7 @@ int main(void)
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
- while (glfwIsWindow(window) == GL_TRUE)
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/title.c b/tests/title.c
index 7b342d94..310713c4 100644
--- a/tests/title.c
+++ b/tests/title.c
@@ -58,7 +58,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback);
- while (glfwIsWindow(window) == GL_TRUE)
+ while (glfwGetCurrentContext())
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
diff --git a/tests/windows.c b/tests/windows.c
index c7ff32b2..601db132 100644
--- a/tests/windows.c
+++ b/tests/windows.c
@@ -32,6 +32,14 @@
#include
#include
+static GLboolean running = GL_TRUE;
+
+static int window_close_callback(GLFWwindow window)
+{
+ running = GL_FALSE;
+ return GL_TRUE;
+}
+
static const char* titles[] =
{
"Foo",
@@ -43,7 +51,6 @@ static const char* titles[] =
int main(void)
{
int i;
- GLboolean running = GL_TRUE;
GLFWwindow windows[4];
if (!glfwInit())
@@ -53,6 +60,8 @@ int main(void)
exit(EXIT_FAILURE);
}
+ glfwSetWindowCloseCallback(window_close_callback);
+
for (i = 0; i < 4; i++)
{
windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
@@ -82,12 +91,6 @@ int main(void)
}
glfwPollEvents();
-
- for (i = 0; i < 4; i++)
- {
- if (!glfwIsWindow(windows[i]))
- running = GL_FALSE;
- }
}
glfwTerminate();