mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Updated some examples and tests to new API.
This commit is contained in:
parent
0c4b67795d
commit
b0ce8006e3
@ -357,7 +357,7 @@ static void drawAllViews( void )
|
|||||||
// Window size callback function
|
// Window size callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void windowSizeFun( int w, int h )
|
static void windowSizeFun( GLFWwindow window, int w, int h )
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h > 0 ? h : 1;
|
height = h > 0 ? h : 1;
|
||||||
@ -369,7 +369,7 @@ static void windowSizeFun( int w, int h )
|
|||||||
// Window refresh callback function
|
// Window refresh callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void windowRefreshFun( void )
|
static void windowRefreshFun( GLFWwindow window )
|
||||||
{
|
{
|
||||||
do_redraw = 1;
|
do_redraw = 1;
|
||||||
}
|
}
|
||||||
@ -379,7 +379,7 @@ static void windowRefreshFun( void )
|
|||||||
// Mouse position callback function
|
// 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
|
// Depending on which view was selected, rotate around different axes
|
||||||
switch( active_view )
|
switch( active_view )
|
||||||
@ -414,7 +414,7 @@ static void mousePosFun( int x, int y )
|
|||||||
// Mouse button callback function
|
// Mouse button callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void mouseButtonFun( int button, int action )
|
static void mouseButtonFun( GLFWwindow window, int button, int action )
|
||||||
{
|
{
|
||||||
// Button clicked?
|
// Button clicked?
|
||||||
if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
|
if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
|
||||||
@ -448,6 +448,8 @@ static void mouseButtonFun( int button, int action )
|
|||||||
|
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
// Initialise GLFW
|
// Initialise GLFW
|
||||||
if( !glfwInit() )
|
if( !glfwInit() )
|
||||||
{
|
{
|
||||||
@ -456,7 +458,8 @@ int main( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open OpenGL window
|
// 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" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -467,19 +470,19 @@ int main( void )
|
|||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
// Set window title
|
// Set window title
|
||||||
glfwSetWindowTitle( "Split view demo" );
|
glfwSetWindowTitle( window, "Split view demo" );
|
||||||
|
|
||||||
// Enable sticky keys
|
// Enable sticky keys
|
||||||
glfwEnable( GLFW_STICKY_KEYS );
|
glfwEnable( window, GLFW_STICKY_KEYS );
|
||||||
|
|
||||||
// Enable mouse cursor (only needed for fullscreen mode)
|
// Enable mouse cursor (only needed for fullscreen mode)
|
||||||
glfwEnable( GLFW_MOUSE_CURSOR );
|
glfwEnable( window, GLFW_MOUSE_CURSOR );
|
||||||
|
|
||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback( windowSizeFun );
|
glfwSetWindowSizeCallback( window, windowSizeFun );
|
||||||
glfwSetWindowRefreshCallback( windowRefreshFun );
|
glfwSetWindowRefreshCallback( window, windowRefreshFun );
|
||||||
glfwSetMousePosCallback( mousePosFun );
|
glfwSetMousePosCallback( window, mousePosFun );
|
||||||
glfwSetMouseButtonCallback( mouseButtonFun );
|
glfwSetMouseButtonCallback( window, mouseButtonFun );
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
do
|
do
|
||||||
@ -500,8 +503,8 @@ int main( void )
|
|||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
} // Check if the ESC key was pressed or the window was closed
|
||||||
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
|
while( glfwIsWindow(window) &&
|
||||||
glfwGetWindowParam( GLFW_OPENED ) );
|
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS );
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -13,6 +13,7 @@ int main( void )
|
|||||||
{
|
{
|
||||||
int width, height, x;
|
int width, height, x;
|
||||||
double t;
|
double t;
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
// Initialise GLFW
|
// Initialise GLFW
|
||||||
if( !glfwInit() )
|
if( !glfwInit() )
|
||||||
@ -22,7 +23,8 @@ int main( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open a window and create its OpenGL context
|
// 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" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
|
|
||||||
@ -30,10 +32,10 @@ int main( void )
|
|||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowTitle( "Spinning Triangle" );
|
glfwSetWindowTitle( window, "Spinning Triangle" );
|
||||||
|
|
||||||
// Ensure we can capture the escape key being pressed below
|
// 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)
|
// Enable vertical sync (on cards that support it)
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
@ -41,10 +43,10 @@ int main( void )
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
t = glfwGetTime();
|
t = glfwGetTime();
|
||||||
glfwGetMousePos( &x, NULL );
|
glfwGetMousePos( window, &x, NULL );
|
||||||
|
|
||||||
// Get window size (may be different than the requested size)
|
// Get window size (may be different than the requested size)
|
||||||
glfwGetWindowSize( &width, &height );
|
glfwGetWindowSize( window, &width, &height );
|
||||||
|
|
||||||
// Special case: avoid division by zero below
|
// Special case: avoid division by zero below
|
||||||
height = height > 0 ? height : 1;
|
height = height > 0 ? height : 1;
|
||||||
@ -81,10 +83,11 @@ int main( void )
|
|||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
} // Check if the ESC key was pressed or the window was closed
|
||||||
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
|
while( glfwIsWindow(window) &&
|
||||||
glfwGetWindowParam( GLFW_OPENED ) );
|
glfwGetKey( window, GLFW_KEY_ESC ) != GLFW_PRESS );
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -250,7 +250,7 @@ void calc( void )
|
|||||||
|
|
||||||
|
|
||||||
/* Handle key strokes */
|
/* 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 )
|
if( action != GLFW_PRESS )
|
||||||
{
|
{
|
||||||
@ -289,7 +289,7 @@ void handle_key_down(int key, int action)
|
|||||||
|
|
||||||
|
|
||||||
/* Callback function for window resize events */
|
/* 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;
|
float ratio = 1.0f;
|
||||||
|
|
||||||
@ -320,6 +320,7 @@ int main(int argc, char* argv[])
|
|||||||
int mode;
|
int mode;
|
||||||
/* Frame time */
|
/* Frame time */
|
||||||
double t, t_old, dt_total;
|
double t, t_old, dt_total;
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
/* Initialize GLFW */
|
/* Initialize GLFW */
|
||||||
if(glfwInit() == GL_FALSE)
|
if(glfwInit() == GL_FALSE)
|
||||||
@ -334,7 +335,8 @@ int main(int argc, char* argv[])
|
|||||||
mode = GLFW_WINDOW;
|
mode = GLFW_WINDOW;
|
||||||
|
|
||||||
/* Open 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");
|
fprintf(stderr, "Could not open window\n");
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -342,16 +344,16 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set title */
|
/* Set title */
|
||||||
glfwSetWindowTitle( "Wave Simulation" );
|
glfwSetWindowTitle( window, "Wave Simulation" );
|
||||||
|
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
/* Keyboard handler */
|
/* Keyboard handler */
|
||||||
glfwSetKeyCallback( handle_key_down );
|
glfwSetKeyCallback( window, handle_key_down );
|
||||||
glfwEnable( GLFW_KEY_REPEAT );
|
glfwEnable( window, GLFW_KEY_REPEAT );
|
||||||
|
|
||||||
/* Window resize handler */
|
/* Window resize handler */
|
||||||
glfwSetWindowSizeCallback( handle_resize );
|
glfwSetWindowSizeCallback( window, handle_resize );
|
||||||
|
|
||||||
/* Initialize OpenGL */
|
/* Initialize OpenGL */
|
||||||
setup_opengl();
|
setup_opengl();
|
||||||
@ -389,8 +391,10 @@ int main(int argc, char* argv[])
|
|||||||
/* Draw wave grid to OpenGL display */
|
/* Draw wave grid to OpenGL display */
|
||||||
draw_screen();
|
draw_screen();
|
||||||
|
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
/* Still running? */
|
/* Still running? */
|
||||||
running = running && glfwGetWindowParam( GLFW_OPENED );
|
running = running && glfwIsWindow( window );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
static int cursor_x = 0, cursor_y = 0;
|
static int cursor_x = 0, cursor_y = 0;
|
||||||
static int window_width = 640, window_height = 480;
|
static int window_width = 640, window_height = 480;
|
||||||
|
|
||||||
static void window_size_callback(int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
window_width = width;
|
window_width = width;
|
||||||
window_height = height;
|
window_height = height;
|
||||||
@ -49,7 +49,7 @@ static void window_size_callback(int width, int height)
|
|||||||
gluOrtho2D(0.f, window_width, 0.f, window_height);
|
gluOrtho2D(0.f, window_width, 0.f, window_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(int x, int y)
|
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
cursor_x = x;
|
cursor_x = x;
|
||||||
cursor_y = y;
|
cursor_y = y;
|
||||||
@ -57,13 +57,16 @@ static void mouse_position_callback(int x, int y)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!glfwOpenWindow(window_width, window_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
window = glfwOpenWindow(window_width, window_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
@ -71,9 +74,9 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowTitle("Cursor Inaccuracy Detector");
|
glfwSetWindowTitle(window, "Cursor Inaccuracy Detector");
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetMousePosCallback(window, mouse_position_callback);
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
@ -81,7 +84,7 @@ int main(void)
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
while (glfwGetWindowParam(GLFW_OPENED))
|
while (glfwIsWindow(window))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
@ -95,6 +98,7 @@ int main(void)
|
|||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -67,6 +67,7 @@ static Param parameters[] =
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i, width, height;
|
int i, width, height;
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
@ -74,7 +75,8 @@ int main(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
window = glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
@ -82,16 +84,20 @@ int main(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwGetWindowSize(&width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
|
||||||
printf("window size: %ix%i\n", width, height);
|
printf("window size: %ix%i\n", width, height);
|
||||||
|
|
||||||
for (i = 0; (size_t) i < sizeof(parameters) / sizeof(parameters[0]); i++)
|
for (i = 0; (size_t) i < sizeof(parameters) / sizeof(parameters[0]); i++)
|
||||||
{
|
{
|
||||||
printf("%s: %i\n", parameters[i].name, glfwGetWindowParam(parameters[i].param));
|
printf("%s: %i\n",
|
||||||
|
parameters[i].name,
|
||||||
|
glfwGetWindowParam(window, parameters[i].param));
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwCloseWindow();
|
glfwCloseWindow(window);
|
||||||
|
window = NULL;
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ static const char* get_character_string(int character)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Window size: %i %i\n",
|
printf("%08x at %0.3f: Window size: %i %i\n",
|
||||||
counter++,
|
counter++,
|
||||||
@ -173,18 +173,18 @@ static void window_size_callback(int width, int height)
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int window_close_callback(void)
|
static int window_close_callback(GLFWwindow window)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
|
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_refresh_callback(void)
|
static void window_refresh_callback(GLFWwindow window)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
|
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_button_callback(int button, int action)
|
static void mouse_button_callback(GLFWwindow window, int button, int action)
|
||||||
{
|
{
|
||||||
const char* name = get_button_name(button);
|
const char* name = get_button_name(button);
|
||||||
|
|
||||||
@ -196,17 +196,17 @@ static void mouse_button_callback(int button, int action)
|
|||||||
printf(" was %s\n", get_action_name(action));
|
printf(" was %s\n", get_action_name(action));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(int x, int y)
|
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
|
printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_wheel_callback(int position)
|
static void mouse_wheel_callback(GLFWwindow window, int position)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Mouse wheel: %i\n", counter++, glfwGetTime(), position);
|
printf("%08x at %0.3f: Mouse wheel: %i\n", counter++, glfwGetTime(), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
const char* name = get_key_name(key);
|
const char* name = get_key_name(key);
|
||||||
|
|
||||||
@ -228,9 +228,9 @@ static void key_callback(int key, int action)
|
|||||||
{
|
{
|
||||||
keyrepeat = !keyrepeat;
|
keyrepeat = !keyrepeat;
|
||||||
if (keyrepeat)
|
if (keyrepeat)
|
||||||
glfwEnable(GLFW_KEY_REPEAT);
|
glfwEnable(window, GLFW_KEY_REPEAT);
|
||||||
else
|
else
|
||||||
glfwDisable(GLFW_KEY_REPEAT);
|
glfwDisable(window, GLFW_KEY_REPEAT);
|
||||||
|
|
||||||
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
|
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
|
||||||
break;
|
break;
|
||||||
@ -240,9 +240,9 @@ static void key_callback(int key, int action)
|
|||||||
{
|
{
|
||||||
systemkeys = !systemkeys;
|
systemkeys = !systemkeys;
|
||||||
if( systemkeys )
|
if( systemkeys )
|
||||||
glfwEnable(GLFW_SYSTEM_KEYS);
|
glfwEnable(window, GLFW_SYSTEM_KEYS);
|
||||||
else
|
else
|
||||||
glfwDisable(GLFW_SYSTEM_KEYS);
|
glfwDisable(window, GLFW_SYSTEM_KEYS);
|
||||||
|
|
||||||
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
|
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
|
||||||
break;
|
break;
|
||||||
@ -250,7 +250,7 @@ static void key_callback(int key, int action)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void char_callback(int character, int action)
|
static void char_callback(GLFWwindow window, int character, int action)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Character 0x%04x", counter++, glfwGetTime(), character);
|
printf("%08x at %0.3f: Character 0x%04x", counter++, glfwGetTime(), character);
|
||||||
|
|
||||||
@ -259,6 +259,8 @@ static void char_callback(int character, int action)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
@ -269,7 +271,8 @@ int main(void)
|
|||||||
|
|
||||||
printf("Library initialized\n");
|
printf("Library initialized\n");
|
||||||
|
|
||||||
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
window = glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
@ -279,28 +282,29 @@ int main(void)
|
|||||||
|
|
||||||
printf("Window opened\n");
|
printf("Window opened\n");
|
||||||
|
|
||||||
glfwSetWindowTitle("Event Linter");
|
glfwSetWindowTitle(window, "Event Linter");
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window, window_close_callback);
|
||||||
glfwSetWindowRefreshCallback(window_refresh_callback);
|
glfwSetWindowRefreshCallback(window, window_refresh_callback);
|
||||||
glfwSetMouseButtonCallback(mouse_button_callback);
|
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetMousePosCallback(window, mouse_position_callback);
|
||||||
glfwSetMouseWheelCallback(mouse_wheel_callback);
|
glfwSetMouseWheelCallback(window, mouse_wheel_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(window, key_callback);
|
||||||
glfwSetCharCallback(char_callback);
|
glfwSetCharCallback(window, char_callback);
|
||||||
|
|
||||||
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
|
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
|
||||||
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
|
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
|
||||||
|
|
||||||
printf("Main loop starting\n");
|
printf("Main loop starting\n");
|
||||||
|
|
||||||
while (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
|
while (glfwIsWindow(window) == GL_TRUE)
|
||||||
{
|
{
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
16
tests/fsaa.c
16
tests/fsaa.c
@ -38,13 +38,15 @@
|
|||||||
#define GL_MULTISAMPLE_ARB 0x809D
|
#define GL_MULTISAMPLE_ARB 0x809D
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void window_size_callback(int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
GLFWwindow window;
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||||
@ -53,7 +55,8 @@ int main(void)
|
|||||||
|
|
||||||
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
|
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
|
||||||
|
|
||||||
if (!glfwOpenWindow(400, 400, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
window = glfwOpenWindow(400, 400, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
|
||||||
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
@ -61,11 +64,11 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowTitle("Aliasing Detector");
|
glfwSetWindowTitle(window, "Aliasing Detector");
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
int samples = glfwGetWindowParam(GLFW_FSAA_SAMPLES);
|
int samples = glfwGetWindowParam(window, GLFW_FSAA_SAMPLES);
|
||||||
if (samples)
|
if (samples)
|
||||||
printf("Context reports FSAA is supported with %i samples\n", samples);
|
printf("Context reports FSAA is supported with %i samples\n", samples);
|
||||||
else
|
else
|
||||||
@ -74,7 +77,7 @@ int main(void)
|
|||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
gluOrtho2D(0.f, 1.f, 0.f, 1.f);
|
gluOrtho2D(0.f, 1.f, 0.f, 1.f);
|
||||||
|
|
||||||
while (glfwGetWindowParam(GLFW_OPENED))
|
while (glfwIsWindow(window))
|
||||||
{
|
{
|
||||||
GLfloat time = (GLfloat) glfwGetTime();
|
GLfloat time = (GLfloat) glfwGetTime();
|
||||||
|
|
||||||
@ -97,6 +100,7 @@ int main(void)
|
|||||||
glRectf(-0.25f, -0.25f, 0.25f, 0.25f);
|
glRectf(-0.25f, -0.25f, 0.25f, 0.25f);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers();
|
||||||
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -36,32 +36,33 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static GLboolean cursor_enabled = GL_TRUE;
|
static GLboolean cursor_enabled = GL_TRUE;
|
||||||
|
static GLFWwindow window_handle = NULL;
|
||||||
|
|
||||||
static GLboolean open_window(void);
|
static GLboolean open_window(void);
|
||||||
|
|
||||||
static void toggle_mouse_cursor(void)
|
static void toggle_mouse_cursor(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (cursor_enabled)
|
if (cursor_enabled)
|
||||||
glfwDisable(GLFW_MOUSE_CURSOR);
|
glfwDisable(window, GLFW_MOUSE_CURSOR);
|
||||||
else
|
else
|
||||||
glfwEnable(GLFW_MOUSE_CURSOR);
|
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
||||||
|
|
||||||
cursor_enabled = !cursor_enabled;
|
cursor_enabled = !cursor_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(int x, int y)
|
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
printf("Mouse moved to: %i %i\n", x, y);
|
printf("Mouse moved to: %i %i\n", x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case GLFW_KEY_SPACE:
|
case GLFW_KEY_SPACE:
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
toggle_mouse_cursor();
|
toggle_mouse_cursor(window);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -70,7 +71,7 @@ static void key_callback(int key, int action)
|
|||||||
{
|
{
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glfwCloseWindow();
|
glfwCloseWindow(window);
|
||||||
open_window();
|
open_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ static void key_callback(int key, int action)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
@ -88,17 +89,18 @@ static GLboolean open_window(void)
|
|||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
|
window_handle = glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
|
||||||
|
if (!window_handle)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
glfwSetWindowTitle("Peter Detector");
|
glfwSetWindowTitle(window_handle, "Peter Detector");
|
||||||
|
|
||||||
glfwGetMousePos(&x, &y);
|
glfwGetMousePos(window_handle, &x, &y);
|
||||||
printf("Mouse position: %i %i\n", x, y);
|
printf("Mouse position: %i %i\n", x, y);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_handle, window_size_callback);
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetMousePosCallback(window_handle, mouse_position_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(window_handle, key_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
@ -122,7 +124,7 @@ int main(void)
|
|||||||
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
|
|
||||||
while (glfwGetWindowParam(GLFW_OPENED))
|
while (glfwIsWindow(window_handle))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user