From 0c4b67795db58b51dbab015389bac27b8127694d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Sep 2010 19:01:32 +0200 Subject: [PATCH] Updated some examples to new API. --- examples/boing.c | 4 ++-- examples/gears.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/boing.c b/examples/boing.c index ef33737d..452695b7 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -40,7 +40,7 @@ /* Prototypes */ void init( void ); void display( void ); -void reshape( int w, int h ); +void reshape( GLFWwindow window, int w, int h ); void DrawBoingBall( void ); void BounceBall( double dt ); void DrawBoingBallBand( GLfloat long_lo, GLfloat long_hi ); @@ -222,7 +222,7 @@ void display(void) /***************************************************************************** * reshape() *****************************************************************************/ -void reshape( int w, int h ) +void reshape( GLFWwindow window, int w, int h ) { glViewport( 0, 0, (GLsizei)w, (GLsizei)h ); diff --git a/examples/gears.c b/examples/gears.c index 5ad484db..4cf12411 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -215,13 +215,13 @@ static void animate(void) /* change view angle, exit upon ESC */ -void key( int k, int action ) +void key( GLFWwindow window, int k, int action ) { if( action != GLFW_PRESS ) return; switch (k) { case 'Z': - if( glfwGetKey( GLFW_KEY_LSHIFT ) ) + if( glfwGetKey( window, GLFW_KEY_LSHIFT ) ) view_rotz -= 5.0; else view_rotz += 5.0; @@ -248,7 +248,7 @@ void key( int k, int action ) /* new window size */ -void reshape( int width, int height ) +void reshape( GLFWwindow window, int width, int height ) { GLfloat h = (GLfloat) height / (GLfloat) width; GLfloat xmax, znear, zfar; @@ -321,29 +321,32 @@ static void init(int argc, char *argv[]) /* program entry */ int main(int argc, char *argv[]) { + GLFWwindow window; + if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); } - if( !glfwOpenWindow( 300,300, 0,0,0,0, 16,0, GLFW_WINDOW ) ) + window = glfwOpenWindow( 300,300, 0,0,0,0, 16,0, GLFW_WINDOW ); + if (!window) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); exit( EXIT_FAILURE ); } - glfwSetWindowTitle( "Gears" ); - glfwEnable( GLFW_KEY_REPEAT ); + glfwSetWindowTitle( window, "Gears" ); + glfwEnable( window, GLFW_KEY_REPEAT ); glfwSwapInterval( 1 ); // Parse command-line options init(argc, argv); // Set callback functions - glfwSetWindowSizeCallback( reshape ); - glfwSetKeyCallback( key ); + glfwSetWindowSizeCallback( window, reshape ); + glfwSetKeyCallback( window, key ); // Main loop while( running ) @@ -356,9 +359,10 @@ int main(int argc, char *argv[]) // Swap buffers glfwSwapBuffers(); + glfwPollEvents(); // Was the window closed? - if( !glfwGetWindowParam( GLFW_OPENED ) ) + if( !glfwIsWindow( window ) ) { running = 0; }