mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Replaced automatic closing with window parameter.
This commit is contained in:
parent
2212cd94bf
commit
2410e2aaf4
|
@ -89,7 +89,6 @@ DRAW_BALL_ENUM drawBallHow;
|
|||
double t;
|
||||
double t_old = 0.f;
|
||||
double dt;
|
||||
static GLboolean running = GL_TRUE;
|
||||
|
||||
/* Random number generator */
|
||||
#ifndef RAND_MAX
|
||||
|
@ -246,16 +245,6 @@ void reshape( GLFWwindow window, int w, int h )
|
|||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Window close callback
|
||||
*****************************************************************************/
|
||||
static int window_close_callback(GLFWwindow window)
|
||||
{
|
||||
running = GL_FALSE;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Draw the Boing ball.
|
||||
*
|
||||
|
@ -588,7 +577,6 @@ int main( void )
|
|||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
glfwSetWindowCloseCallback( window_close_callback );
|
||||
glfwSetWindowSizeCallback( reshape );
|
||||
|
||||
glfwWindowHint(GLFW_DEPTH_BITS, 16);
|
||||
|
@ -611,7 +599,7 @@ int main( void )
|
|||
init();
|
||||
|
||||
/* Main loop */
|
||||
do
|
||||
for (;;)
|
||||
{
|
||||
/* Timing */
|
||||
t = glfwGetTime();
|
||||
|
@ -627,9 +615,10 @@ int main( void )
|
|||
|
||||
/* Check if we are still running */
|
||||
if (glfwGetKey( window, GLFW_KEY_ESCAPE ))
|
||||
running = GL_FALSE;
|
||||
break;
|
||||
if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
break;
|
||||
}
|
||||
while( running );
|
||||
|
||||
glfwTerminate();
|
||||
exit( EXIT_SUCCESS );
|
||||
|
|
|
@ -42,9 +42,6 @@ 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)
|
||||
|
@ -438,17 +435,6 @@ 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
|
||||
//========================================================================
|
||||
|
@ -466,7 +452,6 @@ int main(void)
|
|||
}
|
||||
|
||||
// Set callback functions
|
||||
glfwSetWindowCloseCallback(windowCloseFun);
|
||||
glfwSetWindowSizeCallback(windowSizeFun);
|
||||
glfwSetWindowRefreshCallback(windowRefreshFun);
|
||||
glfwSetCursorPosCallback(cursorPosFun);
|
||||
|
@ -495,7 +480,7 @@ int main(void)
|
|||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||
|
||||
// Main loop
|
||||
do
|
||||
for (;;)
|
||||
{
|
||||
// Only redraw if we need to
|
||||
if (do_redraw)
|
||||
|
@ -512,11 +497,12 @@ 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))
|
||||
running = GL_FALSE;
|
||||
|
||||
} // Check if the ESC key was pressed or the window was closed
|
||||
while (running);
|
||||
break;
|
||||
if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
break;
|
||||
}
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
|
|
@ -10,14 +10,6 @@
|
|||
#define GLFW_INCLUDE_GLU
|
||||
#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 width, height, x;
|
||||
|
@ -44,9 +36,7 @@ int main(void)
|
|||
// Enable vertical sync (on cards that support it)
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
|
||||
do
|
||||
for (;;)
|
||||
{
|
||||
double t = glfwGetTime();
|
||||
glfwGetCursorPos(window, &x, NULL);
|
||||
|
@ -92,11 +82,12 @@ int main(void)
|
|||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
// Check if the ESC key was pressed or the window should be closed
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
|
||||
running = GL_FALSE;
|
||||
|
||||
} // Check if the ESC key was pressed or the window was closed
|
||||
while (running);
|
||||
break;
|
||||
if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
break;
|
||||
}
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
|
|
@ -388,6 +388,7 @@ extern "C" {
|
|||
/* glfwGetWindowParam tokens */
|
||||
#define GLFW_ACTIVE 0x00020001
|
||||
#define GLFW_ICONIFIED 0x00020002
|
||||
#define GLFW_CLOSE_REQUESTED 0x00020003
|
||||
#define GLFW_OPENGL_REVISION 0x00020004
|
||||
|
||||
/* glfwWindowHint tokens */
|
||||
|
|
|
@ -307,6 +307,7 @@ version of GLFW.</p>
|
|||
<li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>
|
||||
<li>Replaced <code>glfwEnable</code> and <code>glfwDisable</code> with <code>glfwGetInputMode</code> and <code>glfwSetInputMode</code></li>
|
||||
<li>Replaced <code>joystick</code> test with graphical version</li>
|
||||
<li>Replaced automatic closing of windows with <code>GLFW_CLOSE_REQUESTED</code> window parameter</li>
|
||||
<li>Made Unicode character input unaffected by <code>GLFW_KEY_REPEAT</code></li>
|
||||
<li>Removed event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li>
|
||||
<li>Removed the Win32 port .def files</li>
|
||||
|
|
|
@ -59,8 +59,7 @@
|
|||
|
||||
- (BOOL)windowShouldClose:(id)sender
|
||||
{
|
||||
window->closeRequested = GL_TRUE;
|
||||
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -127,7 +126,7 @@
|
|||
_GLFWwindow* window;
|
||||
|
||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||
window->closeRequested = GL_TRUE;
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
|
||||
return NSTerminateCancel;
|
||||
}
|
||||
|
|
|
@ -337,6 +337,7 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
|||
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
|
||||
|
||||
// Input event notification (input.c)
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||
|
|
|
@ -532,8 +532,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
|
||||
case WM_CLOSE:
|
||||
{
|
||||
// Flag this window for closing (handled in glfwPollEvents)
|
||||
window->closeRequested = GL_TRUE;
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1249,7 +1248,7 @@ void _glfwPlatformPollEvents(void)
|
|||
window = _glfwLibrary.windowListHead;
|
||||
while (window)
|
||||
{
|
||||
window->closeRequested = GL_TRUE;
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
window = window->next;
|
||||
}
|
||||
|
||||
|
|
44
src/window.c
44
src/window.c
|
@ -44,31 +44,6 @@ static int Max(int a, int b)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Close all GLFW windows with the closed flag set
|
||||
//========================================================================
|
||||
|
||||
static void closeFlaggedWindows(void)
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
|
||||
for (window = _glfwLibrary.windowListHead; window; )
|
||||
{
|
||||
if (window->closeRequested && _glfwLibrary.windowCloseCallback)
|
||||
window->closeRequested = _glfwLibrary.windowCloseCallback(window);
|
||||
|
||||
if (window->closeRequested)
|
||||
{
|
||||
_GLFWwindow* next = window->next;
|
||||
glfwDestroyWindow(window);
|
||||
window = next;
|
||||
}
|
||||
else
|
||||
window = window->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Clear scroll offsets for all windows
|
||||
//========================================================================
|
||||
|
@ -206,6 +181,19 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
|
|||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Register window close request events
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfwLibrary.windowCloseCallback)
|
||||
window->closeRequested = _glfwLibrary.windowCloseCallback(window);
|
||||
else
|
||||
window->closeRequested = GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -662,6 +650,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
|
|||
return window == _glfwLibrary.activeWindow;
|
||||
case GLFW_ICONIFIED:
|
||||
return window->iconified;
|
||||
case GLFW_CLOSE_REQUESTED:
|
||||
return window->closeRequested;
|
||||
case GLFW_REFRESH_RATE:
|
||||
return window->refreshRate;
|
||||
case GLFW_WINDOW_RESIZABLE:
|
||||
|
@ -818,8 +808,6 @@ GLFWAPI void glfwPollEvents(void)
|
|||
clearScrollOffsets();
|
||||
|
||||
_glfwPlatformPollEvents();
|
||||
|
||||
closeFlaggedWindows();
|
||||
}
|
||||
|
||||
|
||||
|
@ -838,7 +826,5 @@ GLFWAPI void glfwWaitEvents(void)
|
|||
clearScrollOffsets();
|
||||
|
||||
_glfwPlatformWaitEvents();
|
||||
|
||||
closeFlaggedWindows();
|
||||
}
|
||||
|
||||
|
|
|
@ -711,7 +711,7 @@ static void processSingleEvent(void)
|
|||
// The window manager was asked to close the window, for example by
|
||||
// the user pressing a 'close' window decoration button
|
||||
|
||||
window->closeRequested = GL_TRUE;
|
||||
_glfwInputWindowCloseRequest(window);
|
||||
}
|
||||
else if (_glfwLibrary.X11.wmPing != None &&
|
||||
(Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmPing)
|
||||
|
|
|
@ -106,7 +106,7 @@ int main(void)
|
|||
|
||||
set_swap_interval(window, swap_interval);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ int main(int argc, char** argv)
|
|||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -48,9 +48,6 @@ static GLboolean closeable = GL_TRUE;
|
|||
// Event index
|
||||
static unsigned int counter = 0;
|
||||
|
||||
// Should we keep running?
|
||||
static GLboolean running = GL_TRUE;
|
||||
|
||||
static const char* get_key_name(int key)
|
||||
{
|
||||
switch (key)
|
||||
|
@ -238,9 +235,6 @@ static int window_close_callback(GLFWwindow window)
|
|||
{
|
||||
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
|
||||
|
||||
if (closeable)
|
||||
running = GL_FALSE;
|
||||
|
||||
return closeable;
|
||||
}
|
||||
|
||||
|
@ -399,7 +393,7 @@ int main(void)
|
|||
|
||||
printf("Main loop starting\n");
|
||||
|
||||
while (running)
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
glfwWaitEvents();
|
||||
|
||||
glfwTerminate();
|
||||
|
|
|
@ -127,7 +127,7 @@ int main(int argc, char** argv)
|
|||
gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
GLfloat time = (GLfloat) glfwGetTime();
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ int main(int argc, char** argv)
|
|||
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ int main(int argc, char** argv)
|
|||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
int width, height;
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ int main(void)
|
|||
glfwSetWindowSizeCallback(window_size_callback);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ int main(void)
|
|||
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window_handle, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ int main(void)
|
|||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ int main(void)
|
|||
|
||||
glfwSetWindowSizeCallback(window_size_callback);
|
||||
|
||||
while (glfwGetCurrentContext())
|
||||
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(window);
|
||||
|
|
|
@ -32,14 +32,6 @@
|
|||
#include <stdio.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[] =
|
||||
{
|
||||
"Foo",
|
||||
|
@ -51,6 +43,7 @@ static const char* titles[] =
|
|||
int main(void)
|
||||
{
|
||||
int i;
|
||||
GLboolean running = GL_TRUE;
|
||||
GLFWwindow windows[4];
|
||||
|
||||
if (!glfwInit())
|
||||
|
@ -60,8 +53,6 @@ int main(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetWindowCloseCallback(window_close_callback);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
|
||||
|
@ -88,6 +79,9 @@ int main(void)
|
|||
glfwMakeContextCurrent(windows[i]);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(windows[i]);
|
||||
|
||||
if (glfwGetWindowParam(windows[i], GLFW_CLOSE_REQUESTED))
|
||||
running = GL_FALSE;
|
||||
}
|
||||
|
||||
glfwPollEvents();
|
||||
|
|
Loading…
Reference in New Issue
Block a user