Removed glfwIsWindow.

This commit is contained in:
Camilla Berglund 2012-08-03 16:20:52 +02:00
parent 1736132bb2
commit 2972cdfeb1
21 changed files with 111 additions and 66 deletions

View File

@ -43,6 +43,7 @@
void init( void ); void init( void );
void display( void ); void display( void );
void reshape( GLFWwindow window, int w, int h ); void reshape( GLFWwindow window, int w, int h );
int window_close_callback(GLFWwindow window);
void DrawBoingBall( void ); void DrawBoingBall( void );
void BounceBall( double dt ); void BounceBall( double dt );
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi ); void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
@ -89,6 +90,7 @@ DRAW_BALL_ENUM drawBallHow;
double t; double t;
double t_old = 0.f; double t_old = 0.f;
double dt; double dt;
static GLboolean running = GL_TRUE;
/* Random number generator */ /* Random number generator */
#ifndef RAND_MAX #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. * Draw the Boing ball.
* *
@ -567,7 +579,6 @@ void DrawGrid( void )
int main( void ) int main( void )
{ {
int running;
GLFWwindow window; GLFWwindow window;
/* Init GLFW */ /* Init GLFW */
@ -587,6 +598,7 @@ int main( void )
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
glfwSetWindowCloseCallback( window_close_callback );
glfwSetWindowSizeCallback( reshape ); glfwSetWindowSizeCallback( reshape );
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
glfwSwapInterval( 1 ); glfwSwapInterval( 1 );
@ -610,7 +622,8 @@ int main( void )
glfwPollEvents(); glfwPollEvents();
/* Check if we are still running */ /* 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 ); while( running );

View File

@ -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 */ /* program & OpenGL initialization */
static void init(int argc, char *argv[]) static void init(int argc, char *argv[])
{ {
@ -346,6 +354,7 @@ int main(int argc, char *argv[])
init(argc, argv); init(argc, argv);
// Set callback functions // Set callback functions
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback( reshape ); glfwSetWindowSizeCallback( reshape );
glfwSetKeyCallback( key ); glfwSetKeyCallback( key );
@ -361,12 +370,6 @@ int main(int argc, char *argv[])
// Swap buffers // Swap buffers
glfwSwapBuffers(); glfwSwapBuffers();
glfwPollEvents(); glfwPollEvents();
// Was the window closed?
if( !glfwIsWindow( window ) )
{
running = 0;
}
} }
// Terminate GLFW // Terminate GLFW

View File

@ -42,6 +42,9 @@ static int rot_x = 0, rot_y = 0, rot_z = 0;
// Do redraw? // Do redraw?
static int do_redraw = 1; static int do_redraw = 1;
// Keep running?
static GLboolean running = GL_TRUE;
//======================================================================== //========================================================================
// Draw a solid torus (use a display list for the model) // 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 // main
//======================================================================== //========================================================================
@ -470,6 +484,7 @@ int main(void)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
// Set callback functions // Set callback functions
glfwSetWindowCloseCallback(windowCloseFun);
glfwSetWindowSizeCallback(windowSizeFun); glfwSetWindowSizeCallback(windowSizeFun);
glfwSetWindowRefreshCallback(windowRefreshFun); glfwSetWindowRefreshCallback(windowRefreshFun);
glfwSetCursorPosCallback(cursorPosFun); glfwSetCursorPosCallback(cursorPosFun);
@ -493,9 +508,11 @@ int main(void)
// Wait for new events // Wait for new events
glfwWaitEvents(); glfwWaitEvents();
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
running = GL_FALSE;
} // Check if the ESC key was pressed or the window was closed } // Check if the ESC key was pressed or the window was closed
while (glfwIsWindow(window) && while (running);
glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);
// Close OpenGL window and terminate GLFW // Close OpenGL window and terminate GLFW
glfwTerminate(); glfwTerminate();

View File

@ -10,6 +10,14 @@
#define GLFW_INCLUDE_GLU #define GLFW_INCLUDE_GLU
#include <GL/glfw3.h> #include <GL/glfw3.h>
static GLboolean running = GL_TRUE;
static int window_close_callback(GLFWwindow window)
{
running = GL_FALSE;
return GL_TRUE;
}
int main(void) int main(void)
{ {
int width, height, x; int width, height, x;
@ -36,6 +44,8 @@ int main(void)
// Enable vertical sync (on cards that support it) // Enable vertical sync (on cards that support it)
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetWindowCloseCallback(window_close_callback);
do do
{ {
double t = glfwGetTime(); double t = glfwGetTime();
@ -82,9 +92,11 @@ int main(void)
glfwSwapBuffers(); glfwSwapBuffers();
glfwPollEvents(); glfwPollEvents();
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
running = GL_FALSE;
} // Check if the ESC key was pressed or the window was closed } // Check if the ESC key was pressed or the window was closed
while (glfwIsWindow(window) && while (running);
glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);
// Close OpenGL window and terminate GLFW // Close OpenGL window and terminate GLFW
glfwTerminate(); glfwTerminate();

View File

@ -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 // main
//======================================================================== //========================================================================
@ -401,6 +412,7 @@ int main(int argc, char* argv[])
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE); glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
// Window resize handler // Window resize handler
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback(window_resize_callback); glfwSetWindowSizeCallback(window_resize_callback);
glfwSetMouseButtonCallback(mouse_button_callback); glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetCursorPosCallback(cursor_position_callback); glfwSetCursorPosCallback(cursor_position_callback);
@ -441,9 +453,6 @@ int main(int argc, char* argv[])
draw_scene(); draw_scene();
glfwPollEvents(); glfwPollEvents();
// Still running?
running = running && glfwIsWindow(window);
} }
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -529,7 +529,6 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp);
/* Window handling */ /* Window handling */
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title, GLFWwindow share); GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title, GLFWwindow share);
GLFWAPI void glfwOpenWindowHint(int target, int hint); GLFWAPI void glfwOpenWindowHint(int target, int hint);
GLFWAPI int glfwIsWindow(GLFWwindow window);
GLFWAPI void glfwCloseWindow(GLFWwindow window); GLFWAPI void glfwCloseWindow(GLFWwindow window);
GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title); GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title);
GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height); GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height);

View File

@ -268,7 +268,6 @@ version of GLFW.</p>
<h3>v3.0</h3> <h3>v3.0</h3>
<ul> <ul>
<li>Added <code>GLFWwindow</code> window handle type and updated window-related functions and callbacks to take a window handle</li> <li>Added <code>GLFWwindow</code> window handle type and updated window-related functions and callbacks to take a window handle</li>
<li>Added <code>glfwIsWindow</code> function for verifying that a given window handle is (still) valid</li>
<li>Added <code>glfwMakeContextCurrent</code> function for making the context of the specified window current</li> <li>Added <code>glfwMakeContextCurrent</code> function for making the context of the specified window current</li>
<li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li> <li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li>
<li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li> <li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>

View File

@ -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 // Set hints for opening the window
//======================================================================== //========================================================================

View File

@ -79,7 +79,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1); glfwSwapInterval(1);
while (glfwIsWindow(window)) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -136,7 +136,7 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0); glClearColor(0.5f, 0.5f, 0.5f, 0);
while (glfwIsWindow(window)) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -385,7 +385,7 @@ int main(void)
printf("Main loop starting\n"); printf("Main loop starting\n");
while (glfwIsWindow(window) == GL_TRUE) while (glfwGetCurrentContext())
glfwWaitEvents(); glfwWaitEvents();
glfwTerminate(); glfwTerminate();

View File

@ -127,7 +127,7 @@ int main(int argc, char** argv)
gluOrtho2D(0.f, 1.f, 0.f, 0.5f); gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
while (glfwIsWindow(window)) while (glfwGetCurrentContext())
{ {
GLfloat time = (GLfloat) glfwGetTime(); GLfloat time = (GLfloat) glfwGetTime();

View File

@ -68,6 +68,7 @@ static void window_key_callback(GLFWwindow window, int key, int action)
static int window_close_callback(GLFWwindow window) static int window_close_callback(GLFWwindow window)
{ {
printf("%0.3f: User closed window\n", glfwGetTime()); printf("%0.3f: User closed window\n", glfwGetTime());
running = GL_FALSE;
return GL_TRUE; return GL_TRUE;
} }
@ -97,7 +98,7 @@ int main(void)
glfwSetKeyCallback(window_key_callback); glfwSetKeyCallback(window_key_callback);
glfwSetWindowCloseCallback(window_close_callback); glfwSetWindowCloseCallback(window_close_callback);
while (running && glfwIsWindow(window) == GL_TRUE) while (running)
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(); glfwSwapBuffers();

View File

@ -151,7 +151,7 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0); glClearColor(0.5f, 0.5f, 0.5f, 0);
while (glfwIsWindow(window)) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -126,7 +126,7 @@ int main(int argc, char** argv)
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
while (glfwIsWindow(window)) while (glfwGetCurrentContext())
{ {
int width, height; int width, height;

View File

@ -44,7 +44,6 @@ typedef struct Joystick
} Joystick; } Joystick;
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1]; static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
static int joystick_count = 0; static int joystick_count = 0;
static void window_size_callback(GLFWwindow window, int width, int height) static void window_size_callback(GLFWwindow window, int width, int height)
@ -199,7 +198,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1); glfwSwapInterval(1);
while (glfwIsWindow(window)) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -127,7 +127,7 @@ int main(void)
glClearColor(0.f, 0.f, 0.f, 0.f); glClearColor(0.f, 0.f, 0.f, 0.f);
while (glfwIsWindow(window_handle)) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -36,12 +36,30 @@
#define WIDTH 400 #define WIDTH 400
#define HEIGHT 400 #define HEIGHT 400
static GLFWwindow windows[2];
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
{ {
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
glfwCloseWindow(window); 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) static GLFWwindow open_window(const char* title, GLFWwindow share)
{ {
GLFWwindow window; GLFWwindow window;
@ -50,6 +68,7 @@ static GLFWwindow open_window(const char* title, GLFWwindow share)
if (!window) if (!window)
return NULL; return NULL;
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback); glfwSetKeyCallback(key_callback);
glfwSwapInterval(1); glfwSwapInterval(1);
@ -112,7 +131,6 @@ static void draw_quad(GLuint texture)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
GLFWwindow windows[2];
GLuint texture; GLuint texture;
int x, y; int x, y;
@ -150,7 +168,7 @@ int main(int argc, char** argv)
glfwGetWindowPos(windows[0], &x, &y); glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y); glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1])) while (windows[0] && windows[1])
{ {
glfwMakeContextCurrent(windows[0]); glfwMakeContextCurrent(windows[0]);
draw_quad(texture); draw_quad(texture);

View File

@ -87,7 +87,7 @@ int main(void)
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
while (glfwIsWindow(window) == GL_TRUE) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -58,7 +58,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowSizeCallback(window_size_callback);
while (glfwIsWindow(window) == GL_TRUE) while (glfwGetCurrentContext())
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(); glfwSwapBuffers();

View File

@ -32,6 +32,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
static GLboolean running = GL_TRUE;
static int window_close_callback(GLFWwindow window)
{
running = GL_FALSE;
return GL_TRUE;
}
static const char* titles[] = static const char* titles[] =
{ {
"Foo", "Foo",
@ -43,7 +51,6 @@ static const char* titles[] =
int main(void) int main(void)
{ {
int i; int i;
GLboolean running = GL_TRUE;
GLFWwindow windows[4]; GLFWwindow windows[4];
if (!glfwInit()) if (!glfwInit())
@ -53,6 +60,8 @@ int main(void)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwSetWindowCloseCallback(window_close_callback);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i], NULL); windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
@ -82,12 +91,6 @@ int main(void)
} }
glfwPollEvents(); glfwPollEvents();
for (i = 0; i < 4; i++)
{
if (!glfwIsWindow(windows[i]))
running = GL_FALSE;
}
} }
glfwTerminate(); glfwTerminate();