Replaced window close parameter with mutable flag.

Replaced the GLFW_SHOULD_CLOSE window parameter with the
glfwWindowShouldClose and glfwSetWindowShouldClose functions, allowing
the setting of the close flag from any point in the program.
This commit is contained in:
Camilla Berglund
2013-03-01 13:45:12 +01:00
parent f8f81e5754
commit 6fadf37bda
26 changed files with 155 additions and 215 deletions
+8 -4
View File
@@ -43,6 +43,7 @@
void init( void );
void display( void );
void reshape( GLFWwindow* window, int w, int h );
void key_callback( GLFWwindow* window, int key, int action );
void DrawBoingBall( void );
void BounceBall( double dt );
void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi );
@@ -244,6 +245,11 @@ void reshape( GLFWwindow* window, int w, int h )
0.0, -1.0, 0.0 ); /* up vector */
}
void key_callback( GLFWwindow* window, int key, int action )
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
/*****************************************************************************
* Draw the Boing ball.
@@ -584,6 +590,7 @@ int main( void )
}
glfwSetWindowSizeCallback(window, reshape);
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval( 1 );
@@ -591,7 +598,6 @@ int main( void )
glfwGetWindowSize(window, &width, &height);
reshape(window, width, height);
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
glfwSetTime( 0.0 );
init();
@@ -612,9 +618,7 @@ int main( void )
glfwPollEvents();
/* Check if we are still running */
if (glfwGetKey( window, GLFW_KEY_ESCAPE ))
break;
if (glfwGetWindowParam(window, GLFW_SHOULD_CLOSE))
if (glfwWindowShouldClose(window))
break;
}
+2 -15
View File
@@ -32,10 +32,6 @@
#define M_PI 3.141592654
#endif
/* The program exits when this is zero.
*/
static int running = 1;
/* If non-zero, the program exits after that many seconds
*/
static int autoexit = 0;
@@ -227,7 +223,7 @@ void key( GLFWwindow* window, int k, int action )
view_rotz += 5.0;
break;
case GLFW_KEY_ESCAPE:
running = 0;
glfwSetWindowShouldClose(window, GL_TRUE);
break;
case GLFW_KEY_UP:
view_rotx += 5.0;
@@ -267,14 +263,6 @@ void reshape( GLFWwindow* window, int width, int height )
}
/* close callback */
static int window_close_callback(GLFWwindow* window)
{
running = 0;
return GL_TRUE;
}
/* program & OpenGL initialization */
static void init(int argc, char *argv[])
{
@@ -349,7 +337,6 @@ int main(int argc, char *argv[])
}
// Set callback functions
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowSizeCallback(window, reshape);
glfwSetKeyCallback(window, key);
@@ -363,7 +350,7 @@ int main(int argc, char *argv[])
init(argc, argv);
// Main loop
while( running )
while( !glfwWindowShouldClose(window) )
{
// Draw gears
draw();
+2 -17
View File
@@ -477,27 +477,13 @@ static void update_mesh(void)
* GLFW callback functions
*********************************************************************/
/* The program runs as long as this is GL_TRUE
*/
static GLboolean running = GL_TRUE;
/* GLFW Window management functions */
static int window_close_callback(GLFWwindow* window)
{
running = GL_FALSE;
/* Disallow window closing
* The window will be closed when the main loop terminates */
return 0;
}
static void key_callback(GLFWwindow* window, int key, int action)
{
switch(key)
{
case GLFW_KEY_ESCAPE:
/* Exit program on Escape */
running = GL_FALSE;
glfwSetWindowShouldClose(window, GL_TRUE);
break;
}
}
@@ -599,7 +585,6 @@ int main(int argc, char** argv)
}
/* Register events callback */
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
@@ -661,7 +646,7 @@ int main(int argc, char** argv)
iter = 0;
dt = last_update_time = glfwGetTime();
while (running)
while (!glfwWindowShouldClose(window))
{
++frame;
/* render the next frame */
+1 -1
View File
@@ -52,7 +52,7 @@ int main(void)
glfwMakeContextCurrent(window);
while (!glfwGetWindowParam(window, GLFW_SHOULD_CLOSE))
while (!glfwWindowShouldClose(window))
{
float ratio;
int width, height;
+9 -12
View File
@@ -434,6 +434,12 @@ static void mouseButtonFun(GLFWwindow* window, int button, int action)
do_redraw = 1;
}
static void key_callback(GLFWwindow* window, int key, int action)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
//========================================================================
// main
@@ -450,8 +456,6 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_DEPTH_BITS, 16);
// Open OpenGL window
window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL);
if (!window)
@@ -467,6 +471,7 @@ int main(void)
glfwSetWindowRefreshCallback(window, windowRefreshFun);
glfwSetCursorPosCallback(window, cursorPosFun);
glfwSetMouseButtonCallback(window, mouseButtonFun);
glfwSetKeyCallback(window, key_callback);
// Enable vsync
glfwMakeContextCurrent(window);
@@ -475,12 +480,6 @@ int main(void)
glfwGetWindowSize(window, &width, &height);
windowSizeFun(window, width, height);
// Enable sticky keys
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
// Enable mouse cursor (only needed for fullscreen mode)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
// Main loop
for (;;)
{
@@ -499,10 +498,8 @@ int main(void)
// Wait for new events
glfwWaitEvents();
// Check if the ESC key was pressed or the window should be closed
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
break;
if (glfwGetWindowParam(window, GLFW_SHOULD_CLOSE))
// Check if the window should be closed
if (glfwWindowShouldClose(window))
break;
}
+2 -15
View File
@@ -28,7 +28,6 @@
GLfloat alpha = 210.f, beta = -70.f;
GLfloat zoom = 2.f;
GLboolean running = GL_TRUE;
GLboolean locked = GL_FALSE;
int cursorX;
@@ -279,7 +278,7 @@ void key_callback(GLFWwindow* window, int key, int action)
switch (key)
{
case GLFW_KEY_ESCAPE:
running = 0;
glfwSetWindowShouldClose(window, GL_TRUE);
break;
case GLFW_KEY_SPACE:
init_grid();
@@ -382,17 +381,6 @@ void window_size_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
//========================================================================
@@ -416,7 +404,6 @@ int main(int argc, char* argv[])
}
glfwSetKeyCallback(window, key_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
@@ -439,7 +426,7 @@ int main(int argc, char* argv[])
// Initialize timer
t_old = glfwGetTime() - 0.01;
while (running)
while (!glfwWindowShouldClose(window))
{
t = glfwGetTime();
dt_total = t - t_old;