Updated some examples and tests to new API.

This commit is contained in:
Camilla Berglund
2010-09-09 19:18:18 +02:00
parent 0c4b67795d
commit b0ce8006e3
8 changed files with 114 additions and 84 deletions

View File

@@ -357,7 +357,7 @@ static void drawAllViews( void )
// Window size callback function
//========================================================================
static void windowSizeFun( int w, int h )
static void windowSizeFun( GLFWwindow window, int w, int h )
{
width = w;
height = h > 0 ? h : 1;
@@ -369,7 +369,7 @@ static void windowSizeFun( int w, int h )
// Window refresh callback function
//========================================================================
static void windowRefreshFun( void )
static void windowRefreshFun( GLFWwindow window )
{
do_redraw = 1;
}
@@ -379,7 +379,7 @@ static void windowRefreshFun( void )
// Mouse position callback function
//========================================================================
static void mousePosFun( int x, int y )
static void mousePosFun( GLFWwindow window, int x, int y )
{
// Depending on which view was selected, rotate around different axes
switch( active_view )
@@ -414,7 +414,7 @@ static void mousePosFun( int x, int y )
// Mouse button callback function
//========================================================================
static void mouseButtonFun( int button, int action )
static void mouseButtonFun( GLFWwindow window, int button, int action )
{
// Button clicked?
if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
@@ -448,6 +448,8 @@ static void mouseButtonFun( int button, int action )
int main( void )
{
GLFWwindow window;
// Initialise GLFW
if( !glfwInit() )
{
@@ -456,7 +458,8 @@ int main( void )
}
// Open OpenGL window
if( !glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW ) )
window = glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW );
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
@@ -467,19 +470,19 @@ int main( void )
glfwSwapInterval( 1 );
// Set window title
glfwSetWindowTitle( "Split view demo" );
glfwSetWindowTitle( window, "Split view demo" );
// Enable sticky keys
glfwEnable( GLFW_STICKY_KEYS );
glfwEnable( window, GLFW_STICKY_KEYS );
// Enable mouse cursor (only needed for fullscreen mode)
glfwEnable( GLFW_MOUSE_CURSOR );
glfwEnable( window, GLFW_MOUSE_CURSOR );
// Set callback functions
glfwSetWindowSizeCallback( windowSizeFun );
glfwSetWindowRefreshCallback( windowRefreshFun );
glfwSetMousePosCallback( mousePosFun );
glfwSetMouseButtonCallback( mouseButtonFun );
glfwSetWindowSizeCallback( window, windowSizeFun );
glfwSetWindowRefreshCallback( window, windowRefreshFun );
glfwSetMousePosCallback( window, mousePosFun );
glfwSetMouseButtonCallback( window, mouseButtonFun );
// Main loop
do
@@ -500,8 +503,8 @@ int main( void )
glfwWaitEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );
while( glfwIsWindow(window) &&
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS );
// Close OpenGL window and terminate GLFW
glfwTerminate();

View File

@@ -13,6 +13,7 @@ int main( void )
{
int width, height, x;
double t;
GLFWwindow window;
// Initialise GLFW
if( !glfwInit() )
@@ -22,7 +23,8 @@ int main( void )
}
// Open a window and create its OpenGL context
if( !glfwOpenWindow( 640, 480, 0,0,0,0, 0,0, GLFW_WINDOW ) )
window = glfwOpenWindow( 640, 480, 0,0,0,0, 0,0, GLFW_WINDOW );
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );
@@ -30,10 +32,10 @@ int main( void )
exit( EXIT_FAILURE );
}
glfwSetWindowTitle( "Spinning Triangle" );
glfwSetWindowTitle( window, "Spinning Triangle" );
// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );
glfwEnable( window, GLFW_STICKY_KEYS );
// Enable vertical sync (on cards that support it)
glfwSwapInterval( 1 );
@@ -41,10 +43,10 @@ int main( void )
do
{
t = glfwGetTime();
glfwGetMousePos( &x, NULL );
glfwGetMousePos( window, &x, NULL );
// Get window size (may be different than the requested size)
glfwGetWindowSize( &width, &height );
glfwGetWindowSize( window, &width, &height );
// Special case: avoid division by zero below
height = height > 0 ? height : 1;
@@ -81,10 +83,11 @@ int main( void )
// Swap buffers
glfwSwapBuffers();
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );
while( glfwIsWindow(window) &&
glfwGetKey( window, GLFW_KEY_ESC ) != GLFW_PRESS );
// Close OpenGL window and terminate GLFW
glfwTerminate();

View File

@@ -250,7 +250,7 @@ void calc( void )
/* Handle key strokes */
void handle_key_down(int key, int action)
void handle_key_down(GLFWwindow window, int key, int action)
{
if( action != GLFW_PRESS )
{
@@ -289,7 +289,7 @@ void handle_key_down(int key, int action)
/* Callback function for window resize events */
void handle_resize( int width, int height )
void handle_resize( GLFWwindow window, int width, int height )
{
float ratio = 1.0f;
@@ -320,6 +320,7 @@ int main(int argc, char* argv[])
int mode;
/* Frame time */
double t, t_old, dt_total;
GLFWwindow window;
/* Initialize GLFW */
if(glfwInit() == GL_FALSE)
@@ -334,7 +335,8 @@ int main(int argc, char* argv[])
mode = GLFW_WINDOW;
/* Open window */
if( glfwOpenWindow(width,height,0,0,0,0,16,0,mode) == GL_FALSE )
window = glfwOpenWindow(width,height,0,0,0,0,16,0,mode);
if (!window)
{
fprintf(stderr, "Could not open window\n");
glfwTerminate();
@@ -342,16 +344,16 @@ int main(int argc, char* argv[])
}
/* Set title */
glfwSetWindowTitle( "Wave Simulation" );
glfwSetWindowTitle( window, "Wave Simulation" );
glfwSwapInterval( 1 );
/* Keyboard handler */
glfwSetKeyCallback( handle_key_down );
glfwEnable( GLFW_KEY_REPEAT );
glfwSetKeyCallback( window, handle_key_down );
glfwEnable( window, GLFW_KEY_REPEAT );
/* Window resize handler */
glfwSetWindowSizeCallback( handle_resize );
glfwSetWindowSizeCallback( window, handle_resize );
/* Initialize OpenGL */
setup_opengl();
@@ -389,8 +391,10 @@ int main(int argc, char* argv[])
/* Draw wave grid to OpenGL display */
draw_screen();
glfwPollEvents();
/* Still running? */
running = running && glfwGetWindowParam( GLFW_OPENED );
running = running && glfwIsWindow( window );
}
glfwTerminate();