diff --git a/CMakeLists.txt b/CMakeLists.txt index d49a2aea..cd712c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(GLFW_VERSION_PATCH "0") set(GLFW_VERSION_EXTRA "") set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}") set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}") +set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib will be installed: lib or lib64") option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) @@ -261,11 +262,11 @@ install(FILES COPYING.txt readme.html # Create and install pkg-config file on supported platforms #-------------------------------------------------------------------- if (_GLFW_X11_GLX OR _GLFW_COCOA_NSGL) - configure_file(${GLFW_SOURCE_DIR}/src/libglfw3.pc.in - ${GLFW_BINARY_DIR}/src/libglfw3.pc @ONLY) + configure_file(${GLFW_SOURCE_DIR}/src/glfw3.pc.in + ${GLFW_BINARY_DIR}/src/glfw3.pc @ONLY) - install(FILES ${GLFW_BINARY_DIR}/src/libglfw3.pc - DESTINATION lib/pkgconfig) + install(FILES ${GLFW_BINARY_DIR}/src/glfw3.pc + DESTINATION lib${LIB_SUFFIX}/pkgconfig) endif() #-------------------------------------------------------------------- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3e7065c6..a3c26beb 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,6 +12,9 @@ include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) +set(GETOPT ${GLFW_SOURCE_DIR}/support/getopt.h + ${GLFW_SOURCE_DIR}/support/getopt.c) + if (APPLE) # Set fancy names for bundles add_executable(Boing MACOSX_BUNDLE boing.c) @@ -29,7 +32,7 @@ else() # Set boring names for executables add_executable(boing WIN32 boing.c) add_executable(gears WIN32 gears.c) - add_executable(heightmap WIN32 heightmap.c getopt.c) + add_executable(heightmap WIN32 heightmap.c ${GETOPT}) add_executable(splitview WIN32 splitview.c) add_executable(triangle WIN32 triangle.c) add_executable(wave WIN32 wave.c) diff --git a/examples/boing.c b/examples/boing.c index 49d602ca..a2094c5f 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -330,7 +330,7 @@ void DrawBoingBall( void ) /***************************************************************************** * Bounce the ball. *****************************************************************************/ -void BounceBall( double dt ) +void BounceBall( double delta_t ) { GLfloat sign; GLfloat deg; @@ -358,8 +358,8 @@ void BounceBall( double dt ) } /* Update ball position */ - ball_x += ball_x_inc * ((float)dt*ANIMATION_SPEED); - ball_y += ball_y_inc * ((float)dt*ANIMATION_SPEED); + ball_x += ball_x_inc * ((float)delta_t*ANIMATION_SPEED); + ball_y += ball_y_inc * ((float)delta_t*ANIMATION_SPEED); /* * Simulate the effects of gravity on Y movement. @@ -567,8 +567,8 @@ void DrawGrid( void ) int main( void ) { - int running; GLFWwindow window; + int width, height; /* Init GLFW */ if( !glfwInit() ) @@ -577,9 +577,11 @@ int main( void ) exit( EXIT_FAILURE ); } - glfwOpenWindowHint(GLFW_DEPTH_BITS, 16); + glfwSetWindowSizeCallback( reshape ); - window = glfwOpenWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL ); + glfwWindowHint(GLFW_DEPTH_BITS, 16); + + window = glfwCreateWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL ); if (!window) { fprintf( stderr, "Failed to open GLFW window\n" ); @@ -587,15 +589,19 @@ int main( void ) exit( EXIT_FAILURE ); } - glfwSetWindowSizeCallback( reshape ); - glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); + glfwMakeContextCurrent(window); glfwSwapInterval( 1 ); + + glfwGetWindowSize(window, &width, &height); + reshape(window, width, height); + + glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); glfwSetTime( 0.0 ); init(); /* Main loop */ - do + for (;;) { /* Timing */ t = glfwGetTime(); @@ -606,13 +612,15 @@ int main( void ) display(); /* Swap buffers */ - glfwSwapBuffers(); + glfwSwapBuffers(window); glfwPollEvents(); /* Check if we are still running */ - running = glfwIsWindow(window) && !glfwGetKey( window, GLFW_KEY_ESCAPE ); + if (glfwGetKey( window, GLFW_KEY_ESCAPE )) + break; + if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) + break; } - while( running ); glfwTerminate(); exit( EXIT_SUCCESS ); diff --git a/examples/gears.c b/examples/gears.c index 53d601f3..cd3cdbb1 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -267,6 +267,14 @@ 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[]) { @@ -322,6 +330,7 @@ static void init(int argc, char *argv[]) int main(int argc, char *argv[]) { GLFWwindow window; + int width, height; if( !glfwInit() ) { @@ -329,9 +338,14 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } - glfwOpenWindowHint(GLFW_DEPTH_BITS, 16); + // Set callback functions + glfwSetWindowCloseCallback(window_close_callback); + glfwSetWindowSizeCallback( reshape ); + glfwSetKeyCallback( key ); - window = glfwOpenWindow( 300, 300, GLFW_WINDOWED, "Gears", NULL ); + glfwWindowHint(GLFW_DEPTH_BITS, 16); + + window = glfwCreateWindow( 300, 300, GLFW_WINDOWED, "Gears", NULL ); if (!window) { fprintf( stderr, "Failed to open GLFW window\n" ); @@ -339,16 +353,17 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } - glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE ); + glfwMakeContextCurrent(window); glfwSwapInterval( 1 ); + glfwGetWindowSize(window, &width, &height); + reshape(window, width, height); + + glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE ); + // Parse command-line options init(argc, argv); - // Set callback functions - glfwSetWindowSizeCallback( reshape ); - glfwSetKeyCallback( key ); - // Main loop while( running ) { @@ -359,14 +374,8 @@ int main(int argc, char *argv[]) animate(); // Swap buffers - glfwSwapBuffers(); + glfwSwapBuffers(window); glfwPollEvents(); - - // Was the window closed? - if( !glfwIsWindow( window ) ) - { - running = 0; - } } // Terminate GLFW diff --git a/examples/heightmap.c b/examples/heightmap.c index e926581a..fce8b8de 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -581,13 +581,13 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } - glfwOpenWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); - glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); - glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); + glfwWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE); + glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); - window = glfwOpenWindow(800, 600, GLFW_WINDOWED, "GLFW OpenGL3 Heightmap demo", NULL); + window = glfwCreateWindow(800, 600, GLFW_WINDOWED, "GLFW OpenGL3 Heightmap demo", NULL); if (! window ) { fprintf(stderr, "ERROR: Unable to create the OpenGL context and associated window\n"); @@ -597,10 +597,12 @@ int main(int argc, char** argv) free(fragment_shader_src); exit(EXIT_FAILURE); } + + /* Register events callback */ glfwSetWindowCloseCallback(window_close_callback); glfwSetKeyCallback(key_callback); - /* Register events callback */ + glfwMakeContextCurrent(window); if (GL_TRUE != init_opengl()) { fprintf(stderr, "ERROR: unable to resolve OpenGL function pointers\n"); @@ -663,7 +665,7 @@ int main(int argc, char** argv) glDrawElements(GL_LINES, 2* MAP_NUM_LINES , GL_UNSIGNED_INT, 0); /* display and process events through callbacks */ - glfwSwapBuffers(); + glfwSwapBuffers(window); glfwPollEvents(); /* Check the frame rate and update the heightmap if needed */ dt = glfwGetTime(); diff --git a/examples/particles.c b/examples/particles.c index 403a9997..c7904e11 100644 --- a/examples/particles.c +++ b/examples/particles.c @@ -1028,7 +1028,7 @@ int main( int argc, char **argv ) } // Open OpenGL fullscreen window - if( !glfwOpenWindow( WIDTH, HEIGHT, 0,0,0,0, 16,0, GLFW_FULLSCREEN ) ) + if( !glfwCreateWindow( WIDTH, HEIGHT, 0,0,0,0, 16,0, GLFW_FULLSCREEN ) ) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); diff --git a/examples/pong3d.c b/examples/pong3d.c index 1d1afd1f..58c9ee20 100644 --- a/examples/pong3d.c +++ b/examples/pong3d.c @@ -810,7 +810,7 @@ int main( void ) } // Open OpenGL window - if( !glfwOpenWindow( WIDTH, HEIGHT, 0,0,0,0, 16,0, GLFW_FULLSCREEN ) ) + if( !glfwCreateWindow( WIDTH, HEIGHT, 0,0,0,0, 16,0, GLFW_FULLSCREEN ) ) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); diff --git a/examples/splitview.c b/examples/splitview.c index c584f9af..4a48a383 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -450,10 +450,16 @@ int main(void) exit(EXIT_FAILURE); } - glfwOpenWindowHint(GLFW_DEPTH_BITS, 16); + // Set callback functions + glfwSetWindowSizeCallback(windowSizeFun); + glfwSetWindowRefreshCallback(windowRefreshFun); + glfwSetCursorPosCallback(cursorPosFun); + glfwSetMouseButtonCallback(mouseButtonFun); + + glfwWindowHint(GLFW_DEPTH_BITS, 16); // Open OpenGL window - window = glfwOpenWindow(500, 500, GLFW_WINDOWED, "Split view demo", NULL); + window = glfwCreateWindow(500, 500, GLFW_WINDOWED, "Split view demo", NULL); if (!window) { fprintf(stderr, "Failed to open GLFW window\n"); @@ -461,22 +467,20 @@ int main(void) } // Enable vsync + glfwMakeContextCurrent(window); glfwSwapInterval(1); + 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); - // Set callback functions - glfwSetWindowSizeCallback(windowSizeFun); - glfwSetWindowRefreshCallback(windowRefreshFun); - glfwSetCursorPosCallback(cursorPosFun); - glfwSetMouseButtonCallback(mouseButtonFun); - // Main loop - do + for (;;) { // Only redraw if we need to if (do_redraw) @@ -485,7 +489,7 @@ int main(void) drawAllViews(); // Swap buffers - glfwSwapBuffers(); + glfwSwapBuffers(window); do_redraw = 0; } @@ -493,9 +497,12 @@ int main(void) // Wait for new events glfwWaitEvents(); - } // Check if the ESC key was pressed or the window was closed - while (glfwIsWindow(window) && - glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS); + // Check if the ESC key was pressed or the window should be closed + if (glfwGetKey(window, GLFW_KEY_ESCAPE)) + break; + if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) + break; + } // Close OpenGL window and terminate GLFW glfwTerminate(); diff --git a/examples/triangle.c b/examples/triangle.c index ee340496..615483a9 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -23,20 +23,21 @@ int main(void) } // Open a window and create its OpenGL context - window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL); + window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL); if (!window) { fprintf(stderr, "Failed to open GLFW window\n"); exit(EXIT_FAILURE); } + // Enable vertical sync (on cards that support it) + glfwMakeContextCurrent(window); + glfwSwapInterval(1); + // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); - // Enable vertical sync (on cards that support it) - glfwSwapInterval(1); - - do + for (;;) { double t = glfwGetTime(); glfwGetCursorPos(window, &x, NULL); @@ -79,12 +80,15 @@ int main(void) glEnd(); // Swap buffers - glfwSwapBuffers(); + glfwSwapBuffers(window); glfwPollEvents(); - } // Check if the ESC key was pressed or the window was closed - while (glfwIsWindow(window) && - glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS); + // Check if the ESC key was pressed or the window should be closed + if (glfwGetKey(window, GLFW_KEY_ESCAPE)) + break; + if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) + break; + } // Close OpenGL window and terminate GLFW glfwTerminate(); diff --git a/examples/wave.c b/examples/wave.c index 54574839..668d54bd 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -145,7 +145,7 @@ void init_grid(void) // Draw scene //======================================================================== -void draw_scene(void) +void draw_scene(GLFWwindow window) { // Clear the color and depth buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -162,7 +162,7 @@ void draw_scene(void) glDrawElements(GL_QUADS, 4 * QUADNUM, GL_UNSIGNED_INT, quad); - glfwSwapBuffers(); + glfwSwapBuffers(window); } @@ -355,7 +355,7 @@ void scroll_callback(GLFWwindow window, double x, double y) // Callback function for window resize events //======================================================================== -void window_resize_callback(GLFWwindow window, int width, int height) +void window_size_callback(GLFWwindow window, int width, int height) { float ratio = 1.f; @@ -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 //======================================================================== @@ -380,6 +391,7 @@ int main(int argc, char* argv[]) { GLFWwindow window; double t, dt_total, t_old; + int width, height; if (!glfwInit()) { @@ -387,24 +399,27 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } - window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL); + glfwSetKeyCallback(key_callback); + glfwSetWindowCloseCallback(window_close_callback); + glfwSetWindowSizeCallback(window_size_callback); + glfwSetMouseButtonCallback(mouse_button_callback); + glfwSetCursorPosCallback(cursor_position_callback); + glfwSetScrollCallback(scroll_callback); + + window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL); if (!window) { fprintf(stderr, "Could not open window\n"); exit(EXIT_FAILURE); } + glfwMakeContextCurrent(window); glfwSwapInterval(1); - // Keyboard handler - glfwSetKeyCallback(key_callback); - glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE); + glfwGetWindowSize(window, &width, &height); + window_size_callback(window, width, height); - // Window resize handler - glfwSetWindowSizeCallback(window_resize_callback); - glfwSetMouseButtonCallback(mouse_button_callback); - glfwSetCursorPosCallback(cursor_position_callback); - glfwSetScrollCallback(scroll_callback); + glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE); // Initialize OpenGL init_opengl(); @@ -438,12 +453,9 @@ int main(int argc, char* argv[]) adjust_grid(); // Draw wave grid to OpenGL display - draw_scene(); + draw_scene(window); glfwPollEvents(); - - // Still running? - running = running && glfwIsWindow(window); } exit(EXIT_SUCCESS); diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 6811d9b5..c3f2a2c0 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -381,18 +381,17 @@ extern "C" { * Other definitions *************************************************************************/ -/* glfwOpenWindow modes */ +/* glfwCreateWindow modes */ #define GLFW_WINDOWED 0x00010001 #define GLFW_FULLSCREEN 0x00010002 /* glfwGetWindowParam tokens */ #define GLFW_ACTIVE 0x00020001 #define GLFW_ICONIFIED 0x00020002 +#define GLFW_CLOSE_REQUESTED 0x00020003 #define GLFW_OPENGL_REVISION 0x00020004 -/* The following constants are used for both glfwGetWindowParam - * and glfwOpenWindowHint - */ +/* glfwWindowHint tokens */ #define GLFW_RED_BITS 0x00021000 #define GLFW_GREEN_BITS 0x00021001 #define GLFW_BLUE_BITS 0x00021002 @@ -408,6 +407,10 @@ extern "C" { #define GLFW_STEREO 0x0002100C #define GLFW_WINDOW_RESIZABLE 0x0002100D #define GLFW_FSAA_SAMPLES 0x0002100E + +/* The following constants are used with both glfwGetWindowParam + * and glfwWindowHint + */ #define GLFW_OPENGL_VERSION_MAJOR 0x0002100F #define GLFW_OPENGL_VERSION_MINOR 0x00021010 #define GLFW_OPENGL_FORWARD_COMPAT 0x00021011 @@ -552,10 +555,9 @@ GLFWAPI void glfwGetGammaRamp(GLFWgammaramp* ramp); 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 glfwWindowHint(int target, int hint); +GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, int mode, const char* title, GLFWwindow share); +GLFWAPI void glfwDestroyWindow(GLFWwindow window); GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title); GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height); GLFWAPI void glfwSetWindowSize(GLFWwindow, int width, int height); @@ -607,7 +609,7 @@ GLFWAPI void glfwSetTime(double time); /* OpenGL support */ GLFWAPI void glfwMakeContextCurrent(GLFWwindow window); GLFWAPI GLFWwindow glfwGetCurrentContext(void); -GLFWAPI void glfwSwapBuffers(void); +GLFWAPI void glfwSwapBuffers(GLFWwindow window); GLFWAPI void glfwSwapInterval(int interval); GLFWAPI int glfwExtensionSupported(const char* extension); GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); diff --git a/readme.html b/readme.html index f399f752..0ef6875a 100644 --- a/readme.html +++ b/readme.html @@ -268,7 +268,6 @@ version of GLFW.

v3.0