mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Merge branch 'master' into multi-monitor
Conflicts: tests/modes.c
This commit is contained in:
commit
39c171a61d
|
@ -8,6 +8,7 @@ set(GLFW_VERSION_PATCH "0")
|
||||||
set(GLFW_VERSION_EXTRA "")
|
set(GLFW_VERSION_EXTRA "")
|
||||||
set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}")
|
set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}")
|
||||||
set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}")
|
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_EXAMPLES "Build the GLFW example programs" ON)
|
||||||
option(GLFW_BUILD_TESTS "Build the GLFW test 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
|
# Create and install pkg-config file on supported platforms
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
if (_GLFW_X11_GLX OR _GLFW_COCOA_NSGL)
|
if (_GLFW_X11_GLX OR _GLFW_COCOA_NSGL)
|
||||||
configure_file(${GLFW_SOURCE_DIR}/src/libglfw3.pc.in
|
configure_file(${GLFW_SOURCE_DIR}/src/glfw3.pc.in
|
||||||
${GLFW_BINARY_DIR}/src/libglfw3.pc @ONLY)
|
${GLFW_BINARY_DIR}/src/glfw3.pc @ONLY)
|
||||||
|
|
||||||
install(FILES ${GLFW_BINARY_DIR}/src/libglfw3.pc
|
install(FILES ${GLFW_BINARY_DIR}/src/glfw3.pc
|
||||||
DESTINATION lib/pkgconfig)
|
DESTINATION lib${LIB_SUFFIX}/pkgconfig)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
|
|
|
@ -12,6 +12,9 @@ include_directories(${GLFW_SOURCE_DIR}/include
|
||||||
${GLFW_SOURCE_DIR}/support
|
${GLFW_SOURCE_DIR}/support
|
||||||
${OPENGL_INCLUDE_DIR})
|
${OPENGL_INCLUDE_DIR})
|
||||||
|
|
||||||
|
set(GETOPT ${GLFW_SOURCE_DIR}/support/getopt.h
|
||||||
|
${GLFW_SOURCE_DIR}/support/getopt.c)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
# Set fancy names for bundles
|
# Set fancy names for bundles
|
||||||
add_executable(Boing MACOSX_BUNDLE boing.c)
|
add_executable(Boing MACOSX_BUNDLE boing.c)
|
||||||
|
@ -29,7 +32,7 @@ else()
|
||||||
# Set boring names for executables
|
# Set boring names for executables
|
||||||
add_executable(boing WIN32 boing.c)
|
add_executable(boing WIN32 boing.c)
|
||||||
add_executable(gears WIN32 gears.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(splitview WIN32 splitview.c)
|
||||||
add_executable(triangle WIN32 triangle.c)
|
add_executable(triangle WIN32 triangle.c)
|
||||||
add_executable(wave WIN32 wave.c)
|
add_executable(wave WIN32 wave.c)
|
||||||
|
|
|
@ -330,7 +330,7 @@ void DrawBoingBall( void )
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Bounce the ball.
|
* Bounce the ball.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void BounceBall( double dt )
|
void BounceBall( double delta_t )
|
||||||
{
|
{
|
||||||
GLfloat sign;
|
GLfloat sign;
|
||||||
GLfloat deg;
|
GLfloat deg;
|
||||||
|
@ -358,8 +358,8 @@ void BounceBall( double dt )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update ball position */
|
/* Update ball position */
|
||||||
ball_x += ball_x_inc * ((float)dt*ANIMATION_SPEED);
|
ball_x += ball_x_inc * ((float)delta_t*ANIMATION_SPEED);
|
||||||
ball_y += ball_y_inc * ((float)dt*ANIMATION_SPEED);
|
ball_y += ball_y_inc * ((float)delta_t*ANIMATION_SPEED);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Simulate the effects of gravity on Y movement.
|
* Simulate the effects of gravity on Y movement.
|
||||||
|
@ -567,8 +567,8 @@ void DrawGrid( void )
|
||||||
|
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
int running;
|
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
int width, height;
|
||||||
|
|
||||||
/* Init GLFW */
|
/* Init GLFW */
|
||||||
if( !glfwInit() )
|
if( !glfwInit() )
|
||||||
|
@ -577,9 +577,11 @@ int main( void )
|
||||||
exit( EXIT_FAILURE );
|
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)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
|
@ -587,15 +589,19 @@ int main( void )
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback( reshape );
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
|
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
reshape(window, width, height);
|
||||||
|
|
||||||
|
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
|
||||||
glfwSetTime( 0.0 );
|
glfwSetTime( 0.0 );
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
do
|
for (;;)
|
||||||
{
|
{
|
||||||
/* Timing */
|
/* Timing */
|
||||||
t = glfwGetTime();
|
t = glfwGetTime();
|
||||||
|
@ -606,13 +612,15 @@ int main( void )
|
||||||
display();
|
display();
|
||||||
|
|
||||||
/* Swap buffers */
|
/* Swap buffers */
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
/* Check if we are still running */
|
/* 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();
|
glfwTerminate();
|
||||||
exit( EXIT_SUCCESS );
|
exit( EXIT_SUCCESS );
|
||||||
|
|
|
@ -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 */
|
/* program & OpenGL initialization */
|
||||||
static void init(int argc, char *argv[])
|
static void init(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -322,6 +330,7 @@ static void init(int argc, char *argv[])
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
int width, height;
|
||||||
|
|
||||||
if( !glfwInit() )
|
if( !glfwInit() )
|
||||||
{
|
{
|
||||||
|
@ -329,9 +338,14 @@ int main(int argc, char *argv[])
|
||||||
exit( EXIT_FAILURE );
|
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)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
|
@ -339,16 +353,17 @@ int main(int argc, char *argv[])
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval( 1 );
|
||||||
|
|
||||||
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
reshape(window, width, height);
|
||||||
|
|
||||||
|
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
|
||||||
|
|
||||||
// Parse command-line options
|
// Parse command-line options
|
||||||
init(argc, argv);
|
init(argc, argv);
|
||||||
|
|
||||||
// Set callback functions
|
|
||||||
glfwSetWindowSizeCallback( reshape );
|
|
||||||
glfwSetKeyCallback( key );
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while( running )
|
while( running )
|
||||||
{
|
{
|
||||||
|
@ -359,14 +374,8 @@ int main(int argc, char *argv[])
|
||||||
animate();
|
animate();
|
||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Was the window closed?
|
|
||||||
if( !glfwIsWindow( window ) )
|
|
||||||
{
|
|
||||||
running = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Terminate GLFW
|
// Terminate GLFW
|
||||||
|
|
|
@ -581,13 +581,13 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwOpenWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE);
|
glfwWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE);
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
|
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 )
|
if (! window )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: Unable to create the OpenGL context and associated window\n");
|
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);
|
free(fragment_shader_src);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Register events callback */
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
/* Register events callback */
|
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
if (GL_TRUE != init_opengl())
|
if (GL_TRUE != init_opengl())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: unable to resolve OpenGL function pointers\n");
|
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);
|
glDrawElements(GL_LINES, 2* MAP_NUM_LINES , GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
/* display and process events through callbacks */
|
/* display and process events through callbacks */
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
/* Check the frame rate and update the heightmap if needed */
|
/* Check the frame rate and update the heightmap if needed */
|
||||||
dt = glfwGetTime();
|
dt = glfwGetTime();
|
||||||
|
|
|
@ -1028,7 +1028,7 @@ int main( int argc, char **argv )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open OpenGL fullscreen window
|
// 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" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
|
@ -810,7 +810,7 @@ int main( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open OpenGL window
|
// 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" );
|
fprintf( stderr, "Failed to open GLFW window\n" );
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
|
@ -450,10 +450,16 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
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
|
// 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)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open GLFW window\n");
|
fprintf(stderr, "Failed to open GLFW window\n");
|
||||||
|
@ -461,22 +467,20 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable vsync
|
// Enable vsync
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
windowSizeFun(window, width, height);
|
||||||
|
|
||||||
// Enable sticky keys
|
// Enable sticky keys
|
||||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||||
|
|
||||||
// Enable mouse cursor (only needed for fullscreen mode)
|
// Enable mouse cursor (only needed for fullscreen mode)
|
||||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
// Set callback functions
|
|
||||||
glfwSetWindowSizeCallback(windowSizeFun);
|
|
||||||
glfwSetWindowRefreshCallback(windowRefreshFun);
|
|
||||||
glfwSetCursorPosCallback(cursorPosFun);
|
|
||||||
glfwSetMouseButtonCallback(mouseButtonFun);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
do
|
for (;;)
|
||||||
{
|
{
|
||||||
// Only redraw if we need to
|
// Only redraw if we need to
|
||||||
if (do_redraw)
|
if (do_redraw)
|
||||||
|
@ -485,7 +489,7 @@ int main(void)
|
||||||
drawAllViews();
|
drawAllViews();
|
||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
|
|
||||||
do_redraw = 0;
|
do_redraw = 0;
|
||||||
}
|
}
|
||||||
|
@ -493,9 +497,12 @@ int main(void)
|
||||||
// Wait for new events
|
// Wait for new events
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
// Check if the ESC key was pressed or the window should be closed
|
||||||
while (glfwIsWindow(window) &&
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
|
||||||
glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);
|
break;
|
||||||
|
if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
|
@ -23,20 +23,21 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a window and create its OpenGL context
|
// 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)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open GLFW window\n");
|
fprintf(stderr, "Failed to open GLFW window\n");
|
||||||
exit(EXIT_FAILURE);
|
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
|
// Ensure we can capture the escape key being pressed below
|
||||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||||
|
|
||||||
// Enable vertical sync (on cards that support it)
|
for (;;)
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
double t = glfwGetTime();
|
double t = glfwGetTime();
|
||||||
glfwGetCursorPos(window, &x, NULL);
|
glfwGetCursorPos(window, &x, NULL);
|
||||||
|
@ -79,12 +80,15 @@ int main(void)
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
// Check if the ESC key was pressed or the window should be closed
|
||||||
while (glfwIsWindow(window) &&
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE))
|
||||||
glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);
|
break;
|
||||||
|
if (glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
|
@ -145,7 +145,7 @@ void init_grid(void)
|
||||||
// Draw scene
|
// Draw scene
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void draw_scene(void)
|
void draw_scene(GLFWwindow window)
|
||||||
{
|
{
|
||||||
// Clear the color and depth buffers
|
// Clear the color and depth buffers
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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);
|
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
|
// 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;
|
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
|
// main
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -380,6 +391,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
double t, dt_total, t_old;
|
double t, dt_total, t_old;
|
||||||
|
int width, height;
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
|
@ -387,24 +399,27 @@ int main(int argc, char* argv[])
|
||||||
exit(EXIT_FAILURE);
|
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)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Could not open window\n");
|
fprintf(stderr, "Could not open window\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
// Keyboard handler
|
glfwGetWindowSize(window, &width, &height);
|
||||||
glfwSetKeyCallback(key_callback);
|
window_size_callback(window, width, height);
|
||||||
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
|
|
||||||
|
|
||||||
// Window resize handler
|
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
|
||||||
glfwSetWindowSizeCallback(window_resize_callback);
|
|
||||||
glfwSetMouseButtonCallback(mouse_button_callback);
|
|
||||||
glfwSetCursorPosCallback(cursor_position_callback);
|
|
||||||
glfwSetScrollCallback(scroll_callback);
|
|
||||||
|
|
||||||
// Initialize OpenGL
|
// Initialize OpenGL
|
||||||
init_opengl();
|
init_opengl();
|
||||||
|
@ -438,12 +453,9 @@ int main(int argc, char* argv[])
|
||||||
adjust_grid();
|
adjust_grid();
|
||||||
|
|
||||||
// Draw wave grid to OpenGL display
|
// Draw wave grid to OpenGL display
|
||||||
draw_scene();
|
draw_scene(window);
|
||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Still running?
|
|
||||||
running = running && glfwIsWindow(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
|
@ -381,18 +381,17 @@ extern "C" {
|
||||||
* Other definitions
|
* Other definitions
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
/* glfwOpenWindow modes */
|
/* glfwCreateWindow modes */
|
||||||
#define GLFW_WINDOWED 0x00010001
|
#define GLFW_WINDOWED 0x00010001
|
||||||
#define GLFW_FULLSCREEN 0x00010002
|
#define GLFW_FULLSCREEN 0x00010002
|
||||||
|
|
||||||
/* glfwGetWindowParam tokens */
|
/* glfwGetWindowParam tokens */
|
||||||
#define GLFW_ACTIVE 0x00020001
|
#define GLFW_ACTIVE 0x00020001
|
||||||
#define GLFW_ICONIFIED 0x00020002
|
#define GLFW_ICONIFIED 0x00020002
|
||||||
|
#define GLFW_CLOSE_REQUESTED 0x00020003
|
||||||
#define GLFW_OPENGL_REVISION 0x00020004
|
#define GLFW_OPENGL_REVISION 0x00020004
|
||||||
|
|
||||||
/* The following constants are used for both glfwGetWindowParam
|
/* glfwWindowHint tokens */
|
||||||
* and glfwOpenWindowHint
|
|
||||||
*/
|
|
||||||
#define GLFW_RED_BITS 0x00021000
|
#define GLFW_RED_BITS 0x00021000
|
||||||
#define GLFW_GREEN_BITS 0x00021001
|
#define GLFW_GREEN_BITS 0x00021001
|
||||||
#define GLFW_BLUE_BITS 0x00021002
|
#define GLFW_BLUE_BITS 0x00021002
|
||||||
|
@ -408,6 +407,10 @@ extern "C" {
|
||||||
#define GLFW_STEREO 0x0002100C
|
#define GLFW_STEREO 0x0002100C
|
||||||
#define GLFW_WINDOW_RESIZABLE 0x0002100D
|
#define GLFW_WINDOW_RESIZABLE 0x0002100D
|
||||||
#define GLFW_FSAA_SAMPLES 0x0002100E
|
#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_MAJOR 0x0002100F
|
||||||
#define GLFW_OPENGL_VERSION_MINOR 0x00021010
|
#define GLFW_OPENGL_VERSION_MINOR 0x00021010
|
||||||
#define GLFW_OPENGL_FORWARD_COMPAT 0x00021011
|
#define GLFW_OPENGL_FORWARD_COMPAT 0x00021011
|
||||||
|
@ -552,10 +555,9 @@ GLFWAPI void glfwGetGammaRamp(GLFWgammaramp* ramp);
|
||||||
GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp);
|
GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp);
|
||||||
|
|
||||||
/* Window handling */
|
/* Window handling */
|
||||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode, const char* title, GLFWwindow share);
|
GLFWAPI void glfwWindowHint(int target, int hint);
|
||||||
GLFWAPI void glfwOpenWindowHint(int target, int hint);
|
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, int mode, const char* title, GLFWwindow share);
|
||||||
GLFWAPI int glfwIsWindow(GLFWwindow window);
|
GLFWAPI void glfwDestroyWindow(GLFWwindow window);
|
||||||
GLFWAPI void glfwCloseWindow(GLFWwindow window);
|
|
||||||
GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title);
|
GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title);
|
||||||
GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height);
|
GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height);
|
||||||
GLFWAPI void glfwSetWindowSize(GLFWwindow, int width, int height);
|
GLFWAPI void glfwSetWindowSize(GLFWwindow, int width, int height);
|
||||||
|
@ -607,7 +609,7 @@ GLFWAPI void glfwSetTime(double time);
|
||||||
/* OpenGL support */
|
/* OpenGL support */
|
||||||
GLFWAPI void glfwMakeContextCurrent(GLFWwindow window);
|
GLFWAPI void glfwMakeContextCurrent(GLFWwindow window);
|
||||||
GLFWAPI GLFWwindow glfwGetCurrentContext(void);
|
GLFWAPI GLFWwindow glfwGetCurrentContext(void);
|
||||||
GLFWAPI void glfwSwapBuffers(void);
|
GLFWAPI void glfwSwapBuffers(GLFWwindow window);
|
||||||
GLFWAPI void glfwSwapInterval(int interval);
|
GLFWAPI void glfwSwapInterval(int interval);
|
||||||
GLFWAPI int glfwExtensionSupported(const char* extension);
|
GLFWAPI int glfwExtensionSupported(const char* extension);
|
||||||
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname);
|
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname);
|
||||||
|
|
|
@ -268,7 +268,6 @@ version of GLFW.</p>
|
||||||
<h3>v3.0</h3>
|
<h3>v3.0</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Added <code>GLFWwindow</code> window handle type and updated window-related functions and callbacks to take a window handle</li>
|
<li>Added <code>GLFWwindow</code> window handle type and updated window-related functions and callbacks to take a window handle</li>
|
||||||
<li>Added <code>glfwIsWindow</code> function for verifying that a given window handle is (still) valid</li>
|
|
||||||
<li>Added <code>glfwMakeContextCurrent</code> function for making the context of the specified window current</li>
|
<li>Added <code>glfwMakeContextCurrent</code> function for making the context of the specified window current</li>
|
||||||
<li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li>
|
<li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li>
|
||||||
<li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>
|
<li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>
|
||||||
|
@ -288,25 +287,27 @@ version of GLFW.</p>
|
||||||
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
||||||
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
|
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
|
||||||
<li>Added <code>glfw3native.h</code> header and platform-specific functions for explicit access to native display, window and context handles</li>
|
<li>Added <code>glfw3native.h</code> header and platform-specific functions for explicit access to native display, window and context handles</li>
|
||||||
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
|
|
||||||
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
|
|
||||||
<li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li>
|
<li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li>
|
||||||
|
<li>Added window parameter to <code>glfwSwapBuffers</code></li>
|
||||||
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
|
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
|
||||||
<li>Changed <code>glfwOpenWindow</code> and <code>glfwSetWindowTitle</code> to use UTF-8 encoded strings</li>
|
<li>Changed <code>glfwOpenWindow</code> and <code>glfwSetWindowTitle</code> to use UTF-8 encoded strings</li>
|
||||||
<li>Changed <code>glfwGetProcAddress</code> to return a (generic) function pointer</li>
|
<li>Changed <code>glfwGetProcAddress</code> to return a (generic) function pointer</li>
|
||||||
<li>Changed <code>glfwGetVideoModes</code> to return a dynamic, unlimited number of video modes</li>
|
<li>Changed <code>glfwGetVideoModes</code> to return a dynamic, unlimited number of video modes</li>
|
||||||
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
||||||
|
<li>Renamed <code>glfwOpenWindowHint</code> to <code>glfwWindowHint</code></li>
|
||||||
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
||||||
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
|
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
|
||||||
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
||||||
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
||||||
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
||||||
<li>Renamed mouse position functions to cursor position equivalents</li>
|
<li>Renamed mouse position functions to cursor position equivalents</li>
|
||||||
|
<li>Replaced <code>glfwOpenWindow</code> and <code>glfwCloseWindow</code> with <code>glfwCreateWindow</code> and <code>glfwDestroyWindow</code></li>
|
||||||
<li>Replaced ad hoc build system with CMake</li>
|
<li>Replaced ad hoc build system with CMake</li>
|
||||||
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
||||||
<li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>
|
<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>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 <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>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 event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li>
|
||||||
<li>Removed the Win32 port .def files</li>
|
<li>Removed the Win32 port .def files</li>
|
||||||
|
@ -320,6 +321,7 @@ version of GLFW.</p>
|
||||||
<li>Removed nonsensical key actions for Unicode character input</li>
|
<li>Removed nonsensical key actions for Unicode character input</li>
|
||||||
<li>Removed <code>GLFWCALL</code> and <code>GLFWAPIENTRY</code> macros for stdcall calling convention</li>
|
<li>Removed <code>GLFWCALL</code> and <code>GLFWAPIENTRY</code> macros for stdcall calling convention</li>
|
||||||
<li>Removed <code>GLFW_ACCELERATED</code> window parameter</li>
|
<li>Removed <code>GLFW_ACCELERATED</code> window parameter</li>
|
||||||
|
<li>Removed default framebuffer attributes from <code>glfwGetWindowParam</code></li>
|
||||||
<li>Bugfix: The default OpenGL version in the <code>glfwinfo</code> test was set to 1.1</li>
|
<li>Bugfix: The default OpenGL version in the <code>glfwinfo</code> test was set to 1.1</li>
|
||||||
<li>Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation</li>
|
<li>Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation</li>
|
||||||
<li>Bugfix: The FSAA test did not check for the availability of <code>GL_ARB_multisample</code></li>
|
<li>Bugfix: The FSAA test did not check for the availability of <code>GL_ARB_multisample</code></li>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
include_directories(${GLFW_SOURCE_DIR}/src
|
include_directories(${GLFW_SOURCE_DIR}/src
|
||||||
${GLFW_BINARY_DIR}/src
|
${GLFW_BINARY_DIR}/src
|
||||||
${glfw_INCLUDE_DIRS})
|
${glfw_INCLUDE_DIRS})
|
||||||
|
@ -59,5 +58,5 @@ if (BUILD_SHARED_LIBS)
|
||||||
target_link_libraries(glfw LINK_INTERFACE_LIBRARIES)
|
target_link_libraries(glfw LINK_INTERFACE_LIBRARIES)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(TARGETS glfw DESTINATION lib)
|
install(TARGETS glfw DESTINATION lib${LIB_SUFFIX} )
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSwapBuffers(void)
|
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
|
||||||
|
|
||||||
// ARP appears to be unnecessary, but this is future-proof
|
// ARP appears to be unnecessary, but this is future-proof
|
||||||
[window->NSGL.context flushBuffer];
|
[window->NSGL.context flushBuffer];
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,7 @@
|
||||||
|
|
||||||
- (BOOL)windowShouldClose:(id)sender
|
- (BOOL)windowShouldClose:(id)sender
|
||||||
{
|
{
|
||||||
window->closeRequested = GL_TRUE;
|
_glfwInputWindowCloseRequest(window);
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
|
||||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||||
window->closeRequested = GL_TRUE;
|
_glfwInputWindowCloseRequest(window);
|
||||||
|
|
||||||
return NSTerminateCancel;
|
return NSTerminateCancel;
|
||||||
}
|
}
|
||||||
|
@ -860,15 +859,13 @@ static GLboolean createContext(_GLFWwindow* window,
|
||||||
// created
|
// created
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
||||||
const _GLFWwndconfig* wndconfig,
|
const _GLFWwndconfig* wndconfig,
|
||||||
const _GLFWfbconfig* fbconfig)
|
const _GLFWfbconfig* fbconfig)
|
||||||
{
|
{
|
||||||
if (!initializeAppKit())
|
if (!initializeAppKit())
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
window->resizable = wndconfig->resizable;
|
|
||||||
|
|
||||||
// We can only have one application delegate, but we only allocate it the
|
// We can only have one application delegate, but we only allocate it the
|
||||||
// first time we create a window to keep all window code in this file
|
// first time we create a window to keep all window code in this file
|
||||||
if (_glfwLibrary.NS.delegate == nil)
|
if (_glfwLibrary.NS.delegate == nil)
|
||||||
|
@ -928,14 +925,10 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
withOptions:nil];
|
withOptions:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
|
|
||||||
NSPoint point = [[NSCursor currentCursor] hotSpot];
|
NSPoint point = [[NSCursor currentCursor] hotSpot];
|
||||||
window->cursorPosX = point.x;
|
window->cursorPosX = point.x;
|
||||||
window->cursorPosY = point.y;
|
window->cursorPosY = point.y;
|
||||||
|
|
||||||
window->resizable = wndconfig->resizable;
|
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +937,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
// Properly kill the window / video display
|
// Properly kill the window / video display
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
[window->NS.object orderOut:nil];
|
[window->NS.object orderOut:nil];
|
||||||
|
|
||||||
|
@ -1041,7 +1034,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||||
// Write back window parameters into GLFW window structure
|
// Write back window parameters into GLFW window structure
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformRefreshWindowParams(void)
|
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,6 @@ void _glfwSetError(int error, const char* format, ...)
|
||||||
char buffer[16384];
|
char buffer[16384];
|
||||||
const char* description;
|
const char* description;
|
||||||
|
|
||||||
// We would use vasprintf here if msvcrt supported it
|
|
||||||
|
|
||||||
if (format)
|
if (format)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -79,7 +79,7 @@ GLFWAPI void glfwTerminate(void)
|
||||||
|
|
||||||
// Close all remaining windows
|
// Close all remaining windows
|
||||||
while (_glfwLibrary.windowListHead)
|
while (_glfwLibrary.windowListHead)
|
||||||
glfwCloseWindow(_glfwLibrary.windowListHead);
|
glfwDestroyWindow(_glfwLibrary.windowListHead);
|
||||||
|
|
||||||
if (!_glfwPlatformTerminate())
|
if (!_glfwPlatformTerminate())
|
||||||
return;
|
return;
|
||||||
|
|
10
src/input.c
10
src/input.c
|
@ -551,16 +551,6 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun)
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwLibrary.cursorPosCallback = cbfun;
|
_glfwLibrary.cursorPosCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
|
||||||
// cursor position
|
|
||||||
if (cbfun)
|
|
||||||
{
|
|
||||||
_GLFWwindow* window;
|
|
||||||
|
|
||||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
|
||||||
cbfun(window, window->cursorPosX, window->cursorPosY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,10 @@ typedef struct _GLFWmonitor _GLFWmonitor;
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow
|
// Window hints, set by glfwWindowHint and consumed by glfwCreateWindow
|
||||||
// A bucket of semi-random stuff lumped together for historical reasons
|
// A bucket of semi-random stuff lumped together for historical reasons
|
||||||
// This is used only by the platform independent code and only to store
|
// This is used only by the platform independent code and only to store
|
||||||
// parameters passed to us by glfwOpenWindowHint
|
// parameters passed to us by glfwWindowHint
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
struct _GLFWhints
|
struct _GLFWhints
|
||||||
{
|
{
|
||||||
|
@ -196,21 +196,6 @@ struct _GLFWwindow
|
||||||
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
|
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
|
||||||
char key[GLFW_KEY_LAST + 1];
|
char key[GLFW_KEY_LAST + 1];
|
||||||
|
|
||||||
// Framebuffer attributes
|
|
||||||
GLint redBits;
|
|
||||||
GLint greenBits;
|
|
||||||
GLint blueBits;
|
|
||||||
GLint alphaBits;
|
|
||||||
GLint depthBits;
|
|
||||||
GLint stencilBits;
|
|
||||||
GLint accumRedBits;
|
|
||||||
GLint accumGreenBits;
|
|
||||||
GLint accumBlueBits;
|
|
||||||
GLint accumAlphaBits;
|
|
||||||
GLint auxBuffers;
|
|
||||||
GLboolean stereo;
|
|
||||||
GLint samples;
|
|
||||||
|
|
||||||
// OpenGL extensions and context attributes
|
// OpenGL extensions and context attributes
|
||||||
int glMajor, glMinor, glRevision;
|
int glMajor, glMinor, glRevision;
|
||||||
GLboolean glForward, glDebug;
|
GLboolean glForward, glDebug;
|
||||||
|
@ -335,8 +320,8 @@ double _glfwPlatformGetTime(void);
|
||||||
void _glfwPlatformSetTime(double time);
|
void _glfwPlatformSetTime(double time);
|
||||||
|
|
||||||
// Window management
|
// Window management
|
||||||
int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);
|
int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);
|
||||||
void _glfwPlatformCloseWindow(_GLFWwindow* window);
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window);
|
||||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
|
||||||
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
|
||||||
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
|
||||||
|
@ -349,9 +334,9 @@ void _glfwPlatformWaitEvents(void);
|
||||||
|
|
||||||
// OpenGL context management
|
// OpenGL context management
|
||||||
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window);
|
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window);
|
||||||
void _glfwPlatformSwapBuffers(void);
|
void _glfwPlatformSwapBuffers(_GLFWwindow* window);
|
||||||
void _glfwPlatformSwapInterval(int interval);
|
void _glfwPlatformSwapInterval(int interval);
|
||||||
void _glfwPlatformRefreshWindowParams(void);
|
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window);
|
||||||
int _glfwPlatformExtensionSupported(const char* extension);
|
int _glfwPlatformExtensionSupported(const char* extension);
|
||||||
GLFWglproc _glfwPlatformGetProcAddress(const char* procname);
|
GLFWglproc _glfwPlatformGetProcAddress(const char* procname);
|
||||||
void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask);
|
void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask);
|
||||||
|
@ -377,6 +362,7 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||||
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||||
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||||
void _glfwInputWindowDamage(_GLFWwindow* window);
|
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||||
|
void _glfwInputWindowCloseRequest(_GLFWwindow* window);
|
||||||
|
|
||||||
// Input event notification (input.c)
|
// Input event notification (input.c)
|
||||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||||
|
|
61
src/opengl.c
61
src/opengl.c
|
@ -244,7 +244,7 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Checks whether the OpenGL part of the window config is sane
|
// Checks whether the OpenGL part of the window config is sane
|
||||||
// It blames glfwOpenWindow because that's the only caller
|
// It blames glfwCreateWindow because that's the only caller
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
|
@ -253,28 +253,28 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
{
|
{
|
||||||
// OpenGL 1.0 is the smallest valid version
|
// OpenGL 1.0 is the smallest valid version
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Invalid OpenGL version requested");
|
"glfwCreateWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5)
|
if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5)
|
||||||
{
|
{
|
||||||
// OpenGL 1.x series ended with version 1.5
|
// OpenGL 1.x series ended with version 1.5
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Invalid OpenGL version requested");
|
"glfwCreateWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1)
|
else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1)
|
||||||
{
|
{
|
||||||
// OpenGL 2.x series ended with version 2.1
|
// OpenGL 2.x series ended with version 2.1
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Invalid OpenGL version requested");
|
"glfwCreateWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3)
|
else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3)
|
||||||
{
|
{
|
||||||
// OpenGL 3.x series ended with version 3.3
|
// OpenGL 3.x series ended with version 3.3
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Invalid OpenGL version requested");
|
"glfwCreateWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -292,7 +292,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
// everything 2.x and let the driver report invalid 2.x versions
|
// everything 2.x and let the driver report invalid 2.x versions
|
||||||
|
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Invalid OpenGL ES 2.x version requested");
|
"glfwCreateWindow: Invalid OpenGL ES 2.x version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE)
|
wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
"glfwOpenWindow: Invalid OpenGL profile requested");
|
"glfwCreateWindow: Invalid OpenGL profile requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,7 +313,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
// and above
|
// and above
|
||||||
|
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Context profiles only exist for "
|
"glfwCreateWindow: Context profiles only exist for "
|
||||||
"OpenGL version 3.2 and above");
|
"OpenGL version 3.2 and above");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
{
|
{
|
||||||
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Forward compatibility only exist for "
|
"glfwCreateWindow: Forward compatibility only exist for "
|
||||||
"OpenGL version 3.0 and above");
|
"OpenGL version 3.0 and above");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
wndconfig->glRobustness != GLFW_OPENGL_LOSE_CONTEXT_ON_RESET)
|
wndconfig->glRobustness != GLFW_OPENGL_LOSE_CONTEXT_ON_RESET)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
"glfwOpenWindow: Invalid OpenGL robustness mode requested");
|
"glfwCreateWindow: Invalid OpenGL robustness mode requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Reads back context properties
|
// Reads back context properties
|
||||||
// It blames glfwOpenWindow because that's the only caller
|
// It blames glfwCreateWindow because that's the only caller
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLboolean _glfwRefreshContextParams(void)
|
GLboolean _glfwRefreshContextParams(void)
|
||||||
|
@ -369,7 +369,7 @@ GLboolean _glfwRefreshContextParams(void)
|
||||||
if (!window->GetStringi)
|
if (!window->GetStringi)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"glfwOpenWindow: Entry point retrieval is broken");
|
"glfwCreateWindow: Entry point retrieval is broken");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,34 +406,13 @@ GLboolean _glfwRefreshContextParams(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glGetIntegerv(GL_RED_BITS, &window->redBits);
|
|
||||||
glGetIntegerv(GL_GREEN_BITS, &window->greenBits);
|
|
||||||
glGetIntegerv(GL_BLUE_BITS, &window->blueBits);
|
|
||||||
|
|
||||||
glGetIntegerv(GL_ALPHA_BITS, &window->alphaBits);
|
|
||||||
glGetIntegerv(GL_DEPTH_BITS, &window->depthBits);
|
|
||||||
glGetIntegerv(GL_STENCIL_BITS, &window->stencilBits);
|
|
||||||
|
|
||||||
glGetIntegerv(GL_ACCUM_RED_BITS, &window->accumRedBits);
|
|
||||||
glGetIntegerv(GL_ACCUM_GREEN_BITS, &window->accumGreenBits);
|
|
||||||
glGetIntegerv(GL_ACCUM_BLUE_BITS, &window->accumBlueBits);
|
|
||||||
glGetIntegerv(GL_ACCUM_ALPHA_BITS, &window->accumAlphaBits);
|
|
||||||
|
|
||||||
glGetIntegerv(GL_AUX_BUFFERS, &window->auxBuffers);
|
|
||||||
glGetBooleanv(GL_STEREO, &window->stereo);
|
|
||||||
|
|
||||||
if (glfwExtensionSupported("GL_ARB_multisample"))
|
|
||||||
glGetIntegerv(GL_SAMPLES_ARB, &window->samples);
|
|
||||||
else
|
|
||||||
window->samples = 0;
|
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Checks whether the current context fulfils the specified requirements
|
// Checks whether the current context fulfils the specified requirements
|
||||||
// It blames glfwOpenWindow because that's the only caller
|
// It blames glfwCreateWindow because that's the only caller
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig)
|
GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig)
|
||||||
|
@ -452,7 +431,7 @@ GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig)
|
||||||
// {GLX|WGL}_ARB_create_context extension and fail here
|
// {GLX|WGL}_ARB_create_context extension and fail here
|
||||||
|
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||||
"glfwOpenWindow: The requested OpenGL version is not available");
|
"glfwCreateWindow: The requested OpenGL version is not available");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,21 +520,17 @@ GLFWAPI GLFWwindow glfwGetCurrentContext(void)
|
||||||
// Swap buffers (double-buffering)
|
// Swap buffers (double-buffering)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSwapBuffers(void)
|
GLFWAPI void glfwSwapBuffers(GLFWwindow handle)
|
||||||
{
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_glfwLibrary.currentWindow)
|
_glfwPlatformSwapBuffers(window);
|
||||||
{
|
|
||||||
_glfwSetError(GLFW_NO_CURRENT_CONTEXT, NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_glfwPlatformSwapBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
// With the Borland C++ compiler, we want to disable FPU exceptions
|
// With the Borland C++ compiler, we want to disable FPU exceptions
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Initialize WGL-specific extensions
|
// Initialize WGL-specific extensions
|
||||||
|
@ -505,7 +508,7 @@ int _glfwCreateContext(_GLFWwindow* window,
|
||||||
|
|
||||||
void _glfwDestroyContext(_GLFWwindow* window)
|
void _glfwDestroyContext(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// This is duplicated from glfwCloseWindow
|
// This is duplicated from glfwDestroyWindow
|
||||||
// TODO: Stop duplicating code
|
// TODO: Stop duplicating code
|
||||||
if (window == _glfwLibrary.currentWindow)
|
if (window == _glfwLibrary.currentWindow)
|
||||||
glfwMakeContextCurrent(NULL);
|
glfwMakeContextCurrent(NULL);
|
||||||
|
@ -545,10 +548,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||||
// Swap buffers (double-buffering)
|
// Swap buffers (double-buffering)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSwapBuffers(void)
|
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
|
||||||
|
|
||||||
SwapBuffers(window->WGL.DC);
|
SwapBuffers(window->WGL.DC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/win32_window.c
Executable file → Normal file
22
src/win32_window.c
Executable file → Normal file
|
@ -31,6 +31,7 @@
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -531,8 +532,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
// Flag this window for closing (handled in glfwPollEvents)
|
_glfwInputWindowCloseRequest(window);
|
||||||
window->closeRequested = GL_TRUE;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,7 +895,7 @@ static int createWindow(_GLFWwindow* window,
|
||||||
if (!wideTitle)
|
if (!wideTitle)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"glfwOpenWindow: Failed to convert title to wide string");
|
"glfwCreateWindow: Failed to convert title to wide string");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -940,7 +940,7 @@ static void destroyWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
_glfwDestroyContext(window);
|
_glfwDestroyContext(window);
|
||||||
|
|
||||||
// This is duplicated from glfwCloseWindow
|
// This is duplicated from glfwDestroyWindow
|
||||||
// TODO: Stop duplicating code
|
// TODO: Stop duplicating code
|
||||||
if (window == _glfwLibrary.activeWindow)
|
if (window == _glfwLibrary.activeWindow)
|
||||||
_glfwLibrary.activeWindow = NULL;
|
_glfwLibrary.activeWindow = NULL;
|
||||||
|
@ -962,14 +962,13 @@ static void destroyWindow(_GLFWwindow* window)
|
||||||
// created
|
// created
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
||||||
const _GLFWwndconfig* wndconfig,
|
const _GLFWwndconfig* wndconfig,
|
||||||
const _GLFWfbconfig* fbconfig)
|
const _GLFWfbconfig* fbconfig)
|
||||||
{
|
{
|
||||||
GLboolean recreateContext = GL_FALSE;
|
GLboolean recreateContext = GL_FALSE;
|
||||||
|
|
||||||
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
window->Win32.desiredRefreshRate = wndconfig->refreshRate;
|
||||||
window->resizable = wndconfig->resizable;
|
|
||||||
|
|
||||||
if (!_glfwLibrary.Win32.classAtom)
|
if (!_glfwLibrary.Win32.classAtom)
|
||||||
{
|
{
|
||||||
|
@ -1092,7 +1091,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
// Properly kill the window / video display
|
// Properly kill the window / video display
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
destroyWindow(window);
|
destroyWindow(window);
|
||||||
|
|
||||||
|
@ -1207,10 +1206,9 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||||
// Write back window parameters into GLFW window structure
|
// Write back window parameters into GLFW window structure
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformRefreshWindowParams(void)
|
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
DEVMODE dm;
|
DEVMODE dm;
|
||||||
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
|
||||||
|
|
||||||
ZeroMemory(&dm, sizeof(DEVMODE));
|
ZeroMemory(&dm, sizeof(DEVMODE));
|
||||||
dm.dmSize = sizeof(DEVMODE);
|
dm.dmSize = sizeof(DEVMODE);
|
||||||
|
@ -1259,7 +1257,7 @@ void _glfwPlatformPollEvents(void)
|
||||||
window = _glfwLibrary.windowListHead;
|
window = _glfwLibrary.windowListHead;
|
||||||
while (window)
|
while (window)
|
||||||
{
|
{
|
||||||
window->closeRequested = GL_TRUE;
|
_glfwInputWindowCloseRequest(window);
|
||||||
window = window->next;
|
window = window->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
159
src/window.c
159
src/window.c
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -44,31 +45,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;
|
|
||||||
glfwCloseWindow(window);
|
|
||||||
window = next;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
window = window->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Clear scroll offsets for all windows
|
// Clear scroll offsets for all windows
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -206,6 +182,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 //////
|
////// GLFW public API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -214,13 +203,14 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
|
||||||
// Create the GLFW window and its associated context
|
// Create the GLFW window and its associated context
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
|
||||||
int mode, const char* title,
|
int mode, const char* title,
|
||||||
GLFWwindow share)
|
GLFWwindow share)
|
||||||
{
|
{
|
||||||
_GLFWfbconfig fbconfig;
|
_GLFWfbconfig fbconfig;
|
||||||
_GLFWwndconfig wndconfig;
|
_GLFWwndconfig wndconfig;
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
_GLFWwindow* previous;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -266,10 +256,13 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||||
if (!_glfwIsValidContextConfig(&wndconfig))
|
if (!_glfwIsValidContextConfig(&wndconfig))
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
// Save the currently current context so it can be restored later
|
||||||
|
previous = glfwGetCurrentContext();
|
||||||
|
|
||||||
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
"glfwOpenWindow: Invalid enum for 'mode' parameter");
|
"glfwCreateWindow: Invalid enum for 'mode' parameter");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +288,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
||||||
"glfwOpenWindow: Failed to allocate window structure");
|
"glfwCreateWindow: Failed to allocate window structure");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,33 +301,41 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||||
window->width = width;
|
window->width = width;
|
||||||
window->height = height;
|
window->height = height;
|
||||||
window->mode = mode;
|
window->mode = mode;
|
||||||
|
window->resizable = wndconfig.resizable;
|
||||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||||
window->systemKeys = GL_TRUE;
|
window->systemKeys = GL_TRUE;
|
||||||
|
|
||||||
// Open the actual window and create its context
|
// Open the actual window and create its context
|
||||||
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
|
if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the actual (as opposed to desired) window parameters
|
// Cache the actual (as opposed to requested) window parameters
|
||||||
_glfwPlatformRefreshWindowParams();
|
_glfwPlatformRefreshWindowParams(window);
|
||||||
|
|
||||||
|
// Cache the actual (as opposed to requested) context parameters
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
if (!_glfwRefreshContextParams())
|
if (!_glfwRefreshContextParams())
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify the context against the requested parameters
|
||||||
if (!_glfwIsValidContext(&wndconfig))
|
if (!_glfwIsValidContext(&wndconfig))
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore the previously current context (or NULL)
|
||||||
|
glfwMakeContextCurrent(previous);
|
||||||
|
|
||||||
// The GLFW specification states that fullscreen windows have the cursor
|
// The GLFW specification states that fullscreen windows have the cursor
|
||||||
// captured by default
|
// captured by default
|
||||||
if (mode == GLFW_FULLSCREEN)
|
if (mode == GLFW_FULLSCREEN)
|
||||||
|
@ -343,45 +344,17 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||||
// Clearing the front buffer to black to avoid garbage pixels left over
|
// Clearing the front buffer to black to avoid garbage pixels left over
|
||||||
// from previous uses of our bit of VRAM
|
// from previous uses of our bit of VRAM
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
_glfwPlatformSwapBuffers();
|
_glfwPlatformSwapBuffers(window);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Returns GL_TRUE if the specified window handle is an actual window
|
// Set hints for creating the window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI int glfwIsWindow(GLFWwindow handle)
|
GLFWAPI void glfwWindowHint(int target, int hint)
|
||||||
{
|
|
||||||
_GLFWwindow* entry;
|
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
|
||||||
{
|
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
|
||||||
return GL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window == NULL)
|
|
||||||
return GL_FALSE;
|
|
||||||
|
|
||||||
for (entry = _glfwLibrary.windowListHead; entry; entry = entry->next)
|
|
||||||
{
|
|
||||||
if (entry == window)
|
|
||||||
return GL_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Set hints for opening the window
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
@ -465,7 +438,7 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
||||||
// Properly kill the window / video display
|
// Properly kill the window / video display
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwCloseWindow(GLFWwindow handle)
|
GLFWAPI void glfwDestroyWindow(GLFWwindow handle)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
|
@ -487,7 +460,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle)
|
||||||
if (window == _glfwLibrary.activeWindow)
|
if (window == _glfwLibrary.activeWindow)
|
||||||
_glfwLibrary.activeWindow = NULL;
|
_glfwLibrary.activeWindow = NULL;
|
||||||
|
|
||||||
_glfwPlatformCloseWindow(window);
|
_glfwPlatformDestroyWindow(window);
|
||||||
|
|
||||||
// Unlink window from global linked list
|
// Unlink window from global linked list
|
||||||
{
|
{
|
||||||
|
@ -573,7 +546,7 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
|
||||||
{
|
{
|
||||||
// Refresh window parameters (may have changed due to changed video
|
// Refresh window parameters (may have changed due to changed video
|
||||||
// modes)
|
// modes)
|
||||||
_glfwPlatformRefreshWindowParams();
|
_glfwPlatformRefreshWindowParams(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,7 +638,7 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
|
||||||
_glfwPlatformRestoreWindow(window);
|
_glfwPlatformRestoreWindow(window);
|
||||||
|
|
||||||
if (window->mode == GLFW_FULLSCREEN)
|
if (window->mode == GLFW_FULLSCREEN)
|
||||||
_glfwPlatformRefreshWindowParams();
|
_glfwPlatformRefreshWindowParams(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -689,36 +662,12 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
|
||||||
return window == _glfwLibrary.activeWindow;
|
return window == _glfwLibrary.activeWindow;
|
||||||
case GLFW_ICONIFIED:
|
case GLFW_ICONIFIED:
|
||||||
return window->iconified;
|
return window->iconified;
|
||||||
case GLFW_RED_BITS:
|
case GLFW_CLOSE_REQUESTED:
|
||||||
return window->redBits;
|
return window->closeRequested;
|
||||||
case GLFW_GREEN_BITS:
|
|
||||||
return window->greenBits;
|
|
||||||
case GLFW_BLUE_BITS:
|
|
||||||
return window->blueBits;
|
|
||||||
case GLFW_ALPHA_BITS:
|
|
||||||
return window->alphaBits;
|
|
||||||
case GLFW_DEPTH_BITS:
|
|
||||||
return window->depthBits;
|
|
||||||
case GLFW_STENCIL_BITS:
|
|
||||||
return window->stencilBits;
|
|
||||||
case GLFW_ACCUM_RED_BITS:
|
|
||||||
return window->accumRedBits;
|
|
||||||
case GLFW_ACCUM_GREEN_BITS:
|
|
||||||
return window->accumGreenBits;
|
|
||||||
case GLFW_ACCUM_BLUE_BITS:
|
|
||||||
return window->accumBlueBits;
|
|
||||||
case GLFW_ACCUM_ALPHA_BITS:
|
|
||||||
return window->accumAlphaBits;
|
|
||||||
case GLFW_AUX_BUFFERS:
|
|
||||||
return window->auxBuffers;
|
|
||||||
case GLFW_STEREO:
|
|
||||||
return window->stereo;
|
|
||||||
case GLFW_REFRESH_RATE:
|
case GLFW_REFRESH_RATE:
|
||||||
return window->refreshRate;
|
return window->refreshRate;
|
||||||
case GLFW_WINDOW_RESIZABLE:
|
case GLFW_WINDOW_RESIZABLE:
|
||||||
return window->resizable;
|
return window->resizable;
|
||||||
case GLFW_FSAA_SAMPLES:
|
|
||||||
return window->samples;
|
|
||||||
case GLFW_OPENGL_VERSION_MAJOR:
|
case GLFW_OPENGL_VERSION_MAJOR:
|
||||||
return window->glMajor;
|
return window->glMajor;
|
||||||
case GLFW_OPENGL_VERSION_MINOR:
|
case GLFW_OPENGL_VERSION_MINOR:
|
||||||
|
@ -789,16 +738,6 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwLibrary.windowSizeCallback = cbfun;
|
_glfwLibrary.windowSizeCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
|
||||||
// window size
|
|
||||||
if (cbfun)
|
|
||||||
{
|
|
||||||
_GLFWwindow* window;
|
|
||||||
|
|
||||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
|
||||||
cbfun(window, window->width, window->height);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -881,8 +820,6 @@ GLFWAPI void glfwPollEvents(void)
|
||||||
clearScrollOffsets();
|
clearScrollOffsets();
|
||||||
|
|
||||||
_glfwPlatformPollEvents();
|
_glfwPlatformPollEvents();
|
||||||
|
|
||||||
closeFlaggedWindows();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -901,7 +838,5 @@ GLFWAPI void glfwWaitEvents(void)
|
||||||
clearScrollOffsets();
|
clearScrollOffsets();
|
||||||
|
|
||||||
_glfwPlatformWaitEvents();
|
_glfwPlatformWaitEvents();
|
||||||
|
|
||||||
closeFlaggedWindows();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ void _glfwInitJoysticks(void)
|
||||||
{
|
{
|
||||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||||
int k, n, fd, joy_count;
|
int k, n, fd, joy_count;
|
||||||
char* joy_base_name;
|
const char* joy_base_name;
|
||||||
char joy_dev_name[20];
|
char joy_dev_name[20];
|
||||||
int driver_version = 0x000800;
|
int driver_version = 0x000800;
|
||||||
char ret_data;
|
char ret_data;
|
||||||
|
|
|
@ -642,10 +642,9 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||||
// Swap OpenGL buffers
|
// Swap OpenGL buffers
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSwapBuffers(void)
|
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
glXSwapBuffers(_glfwLibrary.X11.display,
|
glXSwapBuffers(_glfwLibrary.X11.display, window->X11.handle);
|
||||||
_glfwLibrary.currentWindow->X11.handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,16 +43,6 @@
|
||||||
#define Button6 6
|
#define Button6 6
|
||||||
#define Button7 7
|
#define Button7 7
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Checks whether the event is a MapNotify for the specified window
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
static Bool isMapNotify(Display* d, XEvent* e, char* arg)
|
|
||||||
{
|
|
||||||
return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Translates an X Window key to internal coding
|
// Translates an X Window key to internal coding
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -94,7 +84,6 @@ static int translateChar(XKeyEvent* event)
|
||||||
static GLboolean createWindow(_GLFWwindow* window,
|
static GLboolean createWindow(_GLFWwindow* window,
|
||||||
const _GLFWwndconfig* wndconfig)
|
const _GLFWwndconfig* wndconfig)
|
||||||
{
|
{
|
||||||
XEvent event;
|
|
||||||
unsigned long wamask;
|
unsigned long wamask;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
XVisualInfo* visual = _glfwGetContextVisual(window);
|
XVisualInfo* visual = _glfwGetContextVisual(window);
|
||||||
|
@ -243,8 +232,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||||
|
|
||||||
// Make sure the window is mapped before proceeding
|
// Make sure the window is mapped before proceeding
|
||||||
XMapWindow(_glfwLibrary.X11.display, window->X11.handle);
|
XMapWindow(_glfwLibrary.X11.display, window->X11.handle);
|
||||||
XPeekIfEvent(_glfwLibrary.X11.display, &event, isMapNotify,
|
XFlush(_glfwLibrary.X11.display);
|
||||||
(char*) window->X11.handle);
|
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -723,7 +711,7 @@ static void processSingleEvent(void)
|
||||||
// The window manager was asked to close the window, for example by
|
// The window manager was asked to close the window, for example by
|
||||||
// the user pressing a 'close' window decoration button
|
// the user pressing a 'close' window decoration button
|
||||||
|
|
||||||
window->closeRequested = GL_TRUE;
|
_glfwInputWindowCloseRequest(window);
|
||||||
}
|
}
|
||||||
else if (_glfwLibrary.X11.wmPing != None &&
|
else if (_glfwLibrary.X11.wmPing != None &&
|
||||||
(Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmPing)
|
(Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmPing)
|
||||||
|
@ -888,24 +876,6 @@ static void processSingleEvent(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
////// GLFW internal API //////
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Processes all pending events
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwProcessPendingEvents(void)
|
|
||||||
{
|
|
||||||
int i, count = XPending(_glfwLibrary.X11.display);
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
processSingleEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW platform API //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -915,12 +885,11 @@ void _glfwProcessPendingEvents(void)
|
||||||
// the OpenGL rendering context is created
|
// the OpenGL rendering context is created
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
||||||
const _GLFWwndconfig* wndconfig,
|
const _GLFWwndconfig* wndconfig,
|
||||||
const _GLFWfbconfig* fbconfig)
|
const _GLFWfbconfig* fbconfig)
|
||||||
{
|
{
|
||||||
window->refreshRate = wndconfig->refreshRate;
|
window->refreshRate = wndconfig->refreshRate;
|
||||||
window->resizable = wndconfig->resizable;
|
|
||||||
|
|
||||||
if (!_glfwCreateContext(window, wndconfig, fbconfig))
|
if (!_glfwCreateContext(window, wndconfig, fbconfig))
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
@ -943,9 +912,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
enterFullscreenMode(window);
|
enterFullscreenMode(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the window map event and any other that may have arrived
|
|
||||||
_glfwProcessPendingEvents();
|
|
||||||
|
|
||||||
// Retrieve and set initial cursor position
|
// Retrieve and set initial cursor position
|
||||||
{
|
{
|
||||||
Window cursorWindow, cursorRoot;
|
Window cursorWindow, cursorRoot;
|
||||||
|
@ -974,7 +940,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
||||||
// Properly kill the window/video display
|
// Properly kill the window/video display
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformCloseWindow(_GLFWwindow* window)
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
if (window->mode == GLFW_FULLSCREEN)
|
if (window->mode == GLFW_FULLSCREEN)
|
||||||
leaveFullscreenMode(window);
|
leaveFullscreenMode(window);
|
||||||
|
@ -1138,10 +1104,8 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
||||||
// Read back framebuffer parameters from the context
|
// Read back framebuffer parameters from the context
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformRefreshWindowParams(void)
|
void _glfwPlatformRefreshWindowParams(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
|
||||||
|
|
||||||
// Retrieve refresh rate if possible
|
// Retrieve refresh rate if possible
|
||||||
if (_glfwLibrary.X11.RandR.available)
|
if (_glfwLibrary.X11.RandR.available)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,7 +41,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
|
|
||||||
|
/* 2012-08-12 Lambert Clara <lambert.clara@yahoo.fr>
|
||||||
|
*
|
||||||
|
* Constify third argument of getopt.
|
||||||
|
*/
|
||||||
/* 2011-07-27 Camilla Berglund <elmindreda@elmindreda.org>
|
/* 2011-07-27 Camilla Berglund <elmindreda@elmindreda.org>
|
||||||
*
|
*
|
||||||
* Added _CRT_SECURE_NO_WARNINGS macro.
|
* Added _CRT_SECURE_NO_WARNINGS macro.
|
||||||
|
@ -51,7 +54,6 @@
|
||||||
* Removed unused global static variable 'ID'.
|
* Removed unused global static variable 'ID'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
char* optarg = NULL;
|
char* optarg = NULL;
|
||||||
int optind = 0;
|
int optind = 0;
|
||||||
int opterr = 1;
|
int opterr = 1;
|
||||||
|
@ -103,7 +105,7 @@ static int permute_argv_once()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getopt(int argc, char** argv, char* optstr)
|
int getopt(int argc, char** argv, const char* optstr)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
|
@ -48,7 +48,7 @@ extern int optind;
|
||||||
extern int opterr;
|
extern int opterr;
|
||||||
extern int optopt;
|
extern int optopt;
|
||||||
|
|
||||||
int getopt(int argc, char** argv, char* optstr);
|
int getopt(int argc, char** argv, const char* optstr);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
|
@ -12,16 +12,19 @@ include_directories(${GLFW_SOURCE_DIR}/include
|
||||||
${GLFW_SOURCE_DIR}/support
|
${GLFW_SOURCE_DIR}/support
|
||||||
${OPENGL_INCLUDE_DIR})
|
${OPENGL_INCLUDE_DIR})
|
||||||
|
|
||||||
add_executable(clipboard clipboard.c getopt.c)
|
set(GETOPT ${GLFW_SOURCE_DIR}/support/getopt.h
|
||||||
|
${GLFW_SOURCE_DIR}/support/getopt.c)
|
||||||
|
|
||||||
|
add_executable(clipboard clipboard.c ${GETOPT})
|
||||||
add_executable(defaults defaults.c)
|
add_executable(defaults defaults.c)
|
||||||
add_executable(events events.c)
|
add_executable(events events.c)
|
||||||
add_executable(fsaa fsaa.c getopt.c)
|
add_executable(fsaa fsaa.c ${GETOPT})
|
||||||
add_executable(fsfocus fsfocus.c)
|
add_executable(fsfocus fsfocus.c)
|
||||||
add_executable(gamma gamma.c getopt.c)
|
add_executable(gamma gamma.c ${GETOPT})
|
||||||
add_executable(glfwinfo glfwinfo.c getopt.c)
|
add_executable(glfwinfo glfwinfo.c ${GETOPT})
|
||||||
add_executable(iconify iconify.c getopt.c)
|
add_executable(iconify iconify.c ${GETOPT})
|
||||||
add_executable(joysticks joysticks.c)
|
add_executable(joysticks joysticks.c)
|
||||||
add_executable(modes modes.c getopt.c)
|
add_executable(modes modes.c ${GETOPT})
|
||||||
add_executable(peter peter.c)
|
add_executable(peter peter.c)
|
||||||
add_executable(reopen reopen.c)
|
add_executable(reopen reopen.c)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,19 @@
|
||||||
|
|
||||||
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 int swap_interval = 1;
|
||||||
|
|
||||||
|
static void set_swap_interval(GLFWwindow window, int interval)
|
||||||
|
{
|
||||||
|
char title[256];
|
||||||
|
|
||||||
|
swap_interval = interval;
|
||||||
|
glfwSwapInterval(swap_interval);
|
||||||
|
|
||||||
|
sprintf(title, "Cursor Inaccuracy Detector (interval %i)", swap_interval);
|
||||||
|
|
||||||
|
glfwSetWindowTitle(window, title);
|
||||||
|
}
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
|
@ -56,9 +69,16 @@ static void cursor_position_callback(GLFWwindow window, int x, int y)
|
||||||
cursor_y = y;
|
cursor_y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
|
{
|
||||||
|
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||||
|
set_swap_interval(window, 1 - swap_interval);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
int width, height;
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
|
@ -66,7 +86,11 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "Cursor Inaccuracy Detector", NULL);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
glfwSetKeyCallback(key_callback);
|
||||||
|
|
||||||
|
window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -75,11 +99,14 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetCursorPosCallback(cursor_position_callback);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
window_size_callback(window, width, height);
|
||||||
|
|
||||||
|
set_swap_interval(window, swap_interval);
|
||||||
|
|
||||||
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
@ -90,7 +117,7 @@ int main(void)
|
||||||
glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
|
glVertex2f((GLfloat) cursor_x, (GLfloat) window_height);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case GLFW_KEY_ESCAPE:
|
case GLFW_KEY_ESCAPE:
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLFW_KEY_V:
|
case GLFW_KEY_V:
|
||||||
|
@ -117,7 +117,7 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -126,7 +126,9 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
|
@ -136,14 +138,14 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glColor3f(0.8f, 0.2f, 0.4f);
|
glColor3f(0.8f, 0.2f, 0.4f);
|
||||||
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
|
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
#include <GL/glfw3.h>
|
#include <GL/glfw3.h>
|
||||||
|
#include <GL/glext.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -37,30 +38,38 @@
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int param;
|
int param;
|
||||||
char* name;
|
const char* ext;
|
||||||
} Param;
|
const char* name;
|
||||||
|
} ParamGL;
|
||||||
|
|
||||||
static Param parameters[] =
|
typedef struct
|
||||||
|
{
|
||||||
|
int param;
|
||||||
|
const char* name;
|
||||||
|
} ParamGLFW;
|
||||||
|
|
||||||
|
static ParamGL gl_params[] =
|
||||||
|
{
|
||||||
|
{ GL_RED_BITS, NULL, "red bits" },
|
||||||
|
{ GL_GREEN_BITS, NULL, "green bits" },
|
||||||
|
{ GL_BLUE_BITS, NULL, "blue bits" },
|
||||||
|
{ GL_ALPHA_BITS, NULL, "alpha bits" },
|
||||||
|
{ GL_DEPTH_BITS, NULL, "depth bits" },
|
||||||
|
{ GL_STENCIL_BITS, NULL, "stencil bits" },
|
||||||
|
{ GL_STEREO, NULL, "stereo" },
|
||||||
|
{ GL_SAMPLES_ARB, "GL_ARB_multisample", "FSAA samples" },
|
||||||
|
{ 0, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static ParamGLFW glfw_params[] =
|
||||||
{
|
{
|
||||||
{ GLFW_RED_BITS, "red bits" },
|
|
||||||
{ GLFW_GREEN_BITS, "green bits" },
|
|
||||||
{ GLFW_BLUE_BITS, "blue bits" },
|
|
||||||
{ GLFW_ALPHA_BITS, "alpha bits" },
|
|
||||||
{ GLFW_DEPTH_BITS, "depth bits" },
|
|
||||||
{ GLFW_STENCIL_BITS, "stencil bits" },
|
|
||||||
{ GLFW_REFRESH_RATE, "refresh rate" },
|
{ GLFW_REFRESH_RATE, "refresh rate" },
|
||||||
{ GLFW_ACCUM_RED_BITS, "accum red bits" },
|
|
||||||
{ GLFW_ACCUM_GREEN_BITS, "accum green bits" },
|
|
||||||
{ GLFW_ACCUM_BLUE_BITS, "accum blue bits" },
|
|
||||||
{ GLFW_ACCUM_ALPHA_BITS, "accum alpha bits" },
|
|
||||||
{ GLFW_AUX_BUFFERS, "aux buffers" },
|
|
||||||
{ GLFW_STEREO, "stereo" },
|
|
||||||
{ GLFW_FSAA_SAMPLES, "FSAA samples" },
|
|
||||||
{ GLFW_OPENGL_VERSION_MAJOR, "OpenGL major" },
|
{ GLFW_OPENGL_VERSION_MAJOR, "OpenGL major" },
|
||||||
{ GLFW_OPENGL_VERSION_MINOR, "OpenGL minor" },
|
{ GLFW_OPENGL_VERSION_MINOR, "OpenGL minor" },
|
||||||
{ GLFW_OPENGL_FORWARD_COMPAT, "OpenGL forward compatible" },
|
{ GLFW_OPENGL_FORWARD_COMPAT, "OpenGL forward compatible" },
|
||||||
{ GLFW_OPENGL_DEBUG_CONTEXT, "OpenGL debug context" },
|
{ GLFW_OPENGL_DEBUG_CONTEXT, "OpenGL debug context" },
|
||||||
{ GLFW_OPENGL_PROFILE, "OpenGL profile" },
|
{ GLFW_OPENGL_PROFILE, "OpenGL profile" },
|
||||||
|
{ 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -74,7 +83,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -83,18 +92,34 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwGetWindowSize(window, &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; glfw_params[i].name; i++)
|
||||||
{
|
{
|
||||||
printf("%s: %i\n",
|
printf("%s: %i\n",
|
||||||
parameters[i].name,
|
glfw_params[i].name,
|
||||||
glfwGetWindowParam(window, parameters[i].param));
|
glfwGetWindowParam(window, glfw_params[i].param));
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwCloseWindow(window);
|
for (i = 0; gl_params[i].name; i++)
|
||||||
|
{
|
||||||
|
GLint value = 0;
|
||||||
|
|
||||||
|
if (gl_params[i].ext)
|
||||||
|
{
|
||||||
|
if (!glfwExtensionSupported(gl_params[i].ext))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGetIntegerv(gl_params[i].param, &value);
|
||||||
|
|
||||||
|
printf("%s: %i\n", gl_params[i].name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwDestroyWindow(window);
|
||||||
window = NULL;
|
window = NULL;
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
|
@ -40,9 +40,12 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
|
// These must match the input mode defaults
|
||||||
static GLboolean keyrepeat = GL_FALSE;
|
static GLboolean keyrepeat = GL_FALSE;
|
||||||
static GLboolean systemkeys = GL_TRUE;
|
static GLboolean systemkeys = GL_TRUE;
|
||||||
static GLboolean closeable = GL_TRUE;
|
static GLboolean closeable = GL_TRUE;
|
||||||
|
|
||||||
|
// Event index
|
||||||
static unsigned int counter = 0;
|
static unsigned int counter = 0;
|
||||||
|
|
||||||
static const char* get_key_name(int key)
|
static const char* get_key_name(int key)
|
||||||
|
@ -244,6 +247,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
static int window_close_callback(GLFWwindow window)
|
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 closeable;
|
return closeable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +256,7 @@ 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());
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_focus_callback(GLFWwindow window, int activated)
|
static void window_focus_callback(GLFWwindow window, int activated)
|
||||||
|
@ -367,6 +371,7 @@ void monitor_callback(GLFWmonitor monitor, int event)
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
int width, height;
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
|
@ -391,7 +396,7 @@ int main(void)
|
||||||
glfwSetCharCallback(char_callback);
|
glfwSetCharCallback(char_callback);
|
||||||
glfwSetMonitorDeviceCallback(monitor_callback);
|
glfwSetMonitorDeviceCallback(monitor_callback);
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -402,14 +407,18 @@ int main(void)
|
||||||
|
|
||||||
printf("Window opened\n");
|
printf("Window opened\n");
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
printf("Window size should be %ix%i\n", width, height);
|
||||||
|
|
||||||
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 (glfwIsWindow(window) == GL_TRUE)
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
15
tests/fsaa.c
15
tests/fsaa.c
|
@ -96,9 +96,9 @@ int main(int argc, char** argv)
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
|
||||||
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, samples);
|
glfwWindowHint(GLFW_FSAA_SAMPLES, samples);
|
||||||
|
|
||||||
window = glfwOpenWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
|
window = glfwCreateWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -107,6 +107,9 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
if (!glfwExtensionSupported("GL_ARB_multisample"))
|
if (!glfwExtensionSupported("GL_ARB_multisample"))
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -115,9 +118,7 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSwapInterval(1);
|
glGetIntegerv(GL_SAMPLES_ARB, &samples);
|
||||||
|
|
||||||
samples = glfwGetWindowParam(window, GLFW_FSAA_SAMPLES);
|
|
||||||
if (samples)
|
if (samples)
|
||||||
printf("Context reports FSAA is available with %i samples\n", samples);
|
printf("Context reports FSAA is available with %i samples\n", samples);
|
||||||
else
|
else
|
||||||
|
@ -127,7 +128,7 @@ int main(int argc, char** argv)
|
||||||
gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
|
gluOrtho2D(0.f, 1.f, 0.f, 0.5f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
GLfloat time = (GLfloat) glfwGetTime();
|
GLfloat time = (GLfloat) glfwGetTime();
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ int main(int argc, char** argv)
|
||||||
glEnable(GL_MULTISAMPLE_ARB);
|
glEnable(GL_MULTISAMPLE_ARB);
|
||||||
glRectf(-0.15f, -0.15f, 0.15f, 0.15f);
|
glRectf(-0.15f, -0.15f, 0.15f, 0.15f);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ static void window_key_callback(GLFWwindow window, int key, int action)
|
||||||
static int window_close_callback(GLFWwindow window)
|
static int window_close_callback(GLFWwindow window)
|
||||||
{
|
{
|
||||||
printf("%0.3f: User closed window\n", glfwGetTime());
|
printf("%0.3f: User closed window\n", glfwGetTime());
|
||||||
|
running = GL_FALSE;
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
|
window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -90,17 +91,19 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(window_focus_callback);
|
glfwSetWindowFocusCallback(window_focus_callback);
|
||||||
glfwSetKeyCallback(window_key_callback);
|
glfwSetKeyCallback(window_key_callback);
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
|
|
||||||
while (running && glfwIsWindow(window) == GL_TRUE)
|
while (running)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
#define STEP_SIZE 0.1f
|
#define STEP_SIZE 0.1f
|
||||||
|
|
||||||
static GLfloat gamma = 1.0f;
|
static GLfloat gamma_value = 1.0f;
|
||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
|
@ -46,9 +46,9 @@ static void usage(void)
|
||||||
|
|
||||||
static void set_gamma(float value)
|
static void set_gamma(float value)
|
||||||
{
|
{
|
||||||
gamma = value;
|
gamma_value = value;
|
||||||
printf("Gamma: %f\n", gamma);
|
printf("Gamma: %f\n", gamma_value);
|
||||||
glfwSetGamma(gamma);
|
glfwSetGamma(gamma_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(GLFWwindow window, int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
|
@ -60,22 +60,22 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
case GLFW_KEY_ESCAPE:
|
case GLFW_KEY_ESCAPE:
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GLFW_KEY_KP_ADD:
|
case GLFW_KEY_KP_ADD:
|
||||||
case GLFW_KEY_Q:
|
case GLFW_KEY_Q:
|
||||||
{
|
{
|
||||||
set_gamma(gamma + STEP_SIZE);
|
set_gamma(gamma_value + STEP_SIZE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GLFW_KEY_KP_SUBTRACT:
|
case GLFW_KEY_KP_SUBTRACT:
|
||||||
case GLFW_KEY_W:
|
case GLFW_KEY_W:
|
||||||
{
|
{
|
||||||
if (gamma - STEP_SIZE > 0.f)
|
if (gamma_value - STEP_SIZE > 0.f)
|
||||||
set_gamma(gamma - STEP_SIZE);
|
set_gamma(gamma_value - STEP_SIZE);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (mode == GLFW_FULLSCREEN)
|
if (mode == GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
GLFWvidmode mode;
|
GLFWvidmode desktop_mode;
|
||||||
glfwGetDesktopMode(&mode);
|
glfwGetDesktopMode(&desktop_mode);
|
||||||
width = mode.width;
|
width = desktop_mode.width;
|
||||||
height = mode.height;
|
height = desktop_mode.height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -130,7 +130,7 @@ int main(int argc, char** argv)
|
||||||
height = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(width, height, mode, "Gamma Test", NULL);
|
window = glfwCreateWindow(width, height, mode, "Gamma Test", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -141,7 +141,9 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
set_gamma(1.f);
|
set_gamma(1.f);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
|
@ -151,14 +153,14 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
glClearColor(0.5f, 0.5f, 0.5f, 0);
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glColor3f(0.8f, 0.2f, 0.4f);
|
glColor3f(0.8f, 0.2f, 0.4f);
|
||||||
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
|
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
258
tests/getopt.c
258
tests/getopt.c
|
@ -1,258 +0,0 @@
|
||||||
/*****************************************************************************
|
|
||||||
* getopt.c - competent and free getopt library.
|
|
||||||
* $Header: /cvsroot/freegetopt/freegetopt/getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $
|
|
||||||
*
|
|
||||||
* Copyright (c)2002-2003 Mark K. Kim
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* * Neither the original author of this software nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
||||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
* DAMAGE.
|
|
||||||
*/
|
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "getopt.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* 2011-07-27 Camilla Berglund <elmindreda@elmindreda.org>
|
|
||||||
*
|
|
||||||
* Added _CRT_SECURE_NO_WARNINGS macro.
|
|
||||||
*/
|
|
||||||
/* 2009-10-12 Camilla Berglund <elmindreda@elmindreda.org>
|
|
||||||
*
|
|
||||||
* Removed unused global static variable 'ID'.
|
|
||||||
*/
|
|
||||||
|
|
||||||
char* optarg = NULL;
|
|
||||||
int optind = 0;
|
|
||||||
int opterr = 1;
|
|
||||||
int optopt = '?';
|
|
||||||
|
|
||||||
|
|
||||||
static char** prev_argv = NULL; /* Keep a copy of argv and argc to */
|
|
||||||
static int prev_argc = 0; /* tell if getopt params change */
|
|
||||||
static int argv_index = 0; /* Option we're checking */
|
|
||||||
static int argv_index2 = 0; /* Option argument we're checking */
|
|
||||||
static int opt_offset = 0; /* Index into compounded "-option" */
|
|
||||||
static int dashdash = 0; /* True if "--" option reached */
|
|
||||||
static int nonopt = 0; /* How many nonopts we've found */
|
|
||||||
|
|
||||||
static void increment_index()
|
|
||||||
{
|
|
||||||
/* Move onto the next option */
|
|
||||||
if(argv_index < argv_index2)
|
|
||||||
{
|
|
||||||
while(prev_argv[++argv_index] && prev_argv[argv_index][0] != '-'
|
|
||||||
&& argv_index < argv_index2+1);
|
|
||||||
}
|
|
||||||
else argv_index++;
|
|
||||||
opt_offset = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Permutes argv[] so that the argument currently being processed is moved
|
|
||||||
* to the end.
|
|
||||||
*/
|
|
||||||
static int permute_argv_once()
|
|
||||||
{
|
|
||||||
/* Movability check */
|
|
||||||
if(argv_index + nonopt >= prev_argc) return 1;
|
|
||||||
/* Move the current option to the end, bring the others to front */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char* tmp = prev_argv[argv_index];
|
|
||||||
|
|
||||||
/* Move the data */
|
|
||||||
memmove(&prev_argv[argv_index], &prev_argv[argv_index+1],
|
|
||||||
sizeof(char**) * (prev_argc - argv_index - 1));
|
|
||||||
prev_argv[prev_argc - 1] = tmp;
|
|
||||||
|
|
||||||
nonopt++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int getopt(int argc, char** argv, char* optstr)
|
|
||||||
{
|
|
||||||
int c = 0;
|
|
||||||
|
|
||||||
/* If we have new argv, reinitialize */
|
|
||||||
if(prev_argv != argv || prev_argc != argc)
|
|
||||||
{
|
|
||||||
/* Initialize variables */
|
|
||||||
prev_argv = argv;
|
|
||||||
prev_argc = argc;
|
|
||||||
argv_index = 1;
|
|
||||||
argv_index2 = 1;
|
|
||||||
opt_offset = 1;
|
|
||||||
dashdash = 0;
|
|
||||||
nonopt = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Jump point in case we want to ignore the current argv_index */
|
|
||||||
getopt_top:
|
|
||||||
|
|
||||||
/* Misc. initializations */
|
|
||||||
optarg = NULL;
|
|
||||||
|
|
||||||
/* Dash-dash check */
|
|
||||||
if(argv[argv_index] && !strcmp(argv[argv_index], "--"))
|
|
||||||
{
|
|
||||||
dashdash = 1;
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we're at the end of argv, that's it. */
|
|
||||||
if(argv[argv_index] == NULL)
|
|
||||||
{
|
|
||||||
c = -1;
|
|
||||||
}
|
|
||||||
/* Are we looking at a string? Single dash is also a string */
|
|
||||||
else if(dashdash || argv[argv_index][0] != '-' || !strcmp(argv[argv_index], "-"))
|
|
||||||
{
|
|
||||||
/* If we want a string... */
|
|
||||||
if(optstr[0] == '-')
|
|
||||||
{
|
|
||||||
c = 1;
|
|
||||||
optarg = argv[argv_index];
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
/* If we really don't want it (we're in POSIX mode), we're done */
|
|
||||||
else if(optstr[0] == '+' || getenv("POSIXLY_CORRECT"))
|
|
||||||
{
|
|
||||||
c = -1;
|
|
||||||
|
|
||||||
/* Everything else is a non-opt argument */
|
|
||||||
nonopt = argc - argv_index;
|
|
||||||
}
|
|
||||||
/* If we mildly don't want it, then move it back */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!permute_argv_once()) goto getopt_top;
|
|
||||||
else c = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Otherwise we're looking at an option */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char* opt_ptr = NULL;
|
|
||||||
|
|
||||||
/* Grab the option */
|
|
||||||
c = argv[argv_index][opt_offset++];
|
|
||||||
|
|
||||||
/* Is the option in the optstr? */
|
|
||||||
if(optstr[0] == '-') opt_ptr = strchr(optstr+1, c);
|
|
||||||
else opt_ptr = strchr(optstr, c);
|
|
||||||
/* Invalid argument */
|
|
||||||
if(!opt_ptr)
|
|
||||||
{
|
|
||||||
if(opterr)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
|
|
||||||
}
|
|
||||||
|
|
||||||
optopt = c;
|
|
||||||
c = '?';
|
|
||||||
|
|
||||||
/* Move onto the next option */
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
/* Option takes argument */
|
|
||||||
else if(opt_ptr[1] == ':')
|
|
||||||
{
|
|
||||||
/* ie, -oARGUMENT, -xxxoARGUMENT, etc. */
|
|
||||||
if(argv[argv_index][opt_offset] != '\0')
|
|
||||||
{
|
|
||||||
optarg = &argv[argv_index][opt_offset];
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
/* ie, -o ARGUMENT (only if it's a required argument) */
|
|
||||||
else if(opt_ptr[2] != ':')
|
|
||||||
{
|
|
||||||
/* One of those "you're not expected to understand this" moment */
|
|
||||||
if(argv_index2 < argv_index) argv_index2 = argv_index;
|
|
||||||
while(argv[++argv_index2] && argv[argv_index2][0] == '-');
|
|
||||||
optarg = argv[argv_index2];
|
|
||||||
|
|
||||||
/* Don't cross into the non-option argument list */
|
|
||||||
if(argv_index2 + nonopt >= prev_argc) optarg = NULL;
|
|
||||||
|
|
||||||
/* Move onto the next option */
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Move onto the next option */
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In case we got no argument for an option with required argument */
|
|
||||||
if(optarg == NULL && opt_ptr[2] != ':')
|
|
||||||
{
|
|
||||||
optopt = c;
|
|
||||||
c = '?';
|
|
||||||
|
|
||||||
if(opterr)
|
|
||||||
{
|
|
||||||
fprintf(stderr,"%s: option requires an argument -- %c\n",
|
|
||||||
argv[0], optopt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Option does not take argument */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Next argv_index */
|
|
||||||
if(argv[argv_index][opt_offset] == '\0')
|
|
||||||
{
|
|
||||||
increment_index();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate optind */
|
|
||||||
if(c == -1)
|
|
||||||
{
|
|
||||||
optind = argc - nonopt;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
optind = argv_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* vim:ts=3
|
|
||||||
*/
|
|
|
@ -1,63 +0,0 @@
|
||||||
/*****************************************************************************
|
|
||||||
* getopt.h - competent and free getopt library.
|
|
||||||
* $Header: /cvsroot/freegetopt/freegetopt/getopt.h,v 1.2 2003/10/26 03:10:20 vindaci Exp $
|
|
||||||
*
|
|
||||||
* Copyright (c)2002-2003 Mark K. Kim
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* * Neither the original author of this software nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
||||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
* DAMAGE.
|
|
||||||
*/
|
|
||||||
#ifndef GETOPT_H_
|
|
||||||
#define GETOPT_H_
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern char* optarg;
|
|
||||||
extern int optind;
|
|
||||||
extern int opterr;
|
|
||||||
extern int optopt;
|
|
||||||
|
|
||||||
int getopt(int argc, char** argv, char* optstr);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* GETOPT_H_ */
|
|
||||||
|
|
||||||
|
|
||||||
/* vim:ts=3
|
|
||||||
*/
|
|
|
@ -191,29 +191,31 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (major != 1 || minor != 0)
|
if (major != 1 || minor != 0)
|
||||||
{
|
{
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
|
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
||||||
|
|
||||||
if (forward)
|
if (forward)
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
|
|
||||||
if (profile != 0)
|
if (profile != 0)
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, profile);
|
||||||
|
|
||||||
if (strategy)
|
if (strategy)
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
|
glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
|
||||||
|
|
||||||
// We assume here that we stand a better chance of success by leaving all
|
// We assume here that we stand a better chance of success by leaving all
|
||||||
// possible details of pixel format selection to GLFW
|
// possible details of pixel format selection to GLFW
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
// Report GLFW version
|
// Report GLFW version
|
||||||
|
|
||||||
glfwGetVersion(&major, &minor, &revision);
|
glfwGetVersion(&major, &minor, &revision);
|
||||||
|
|
|
@ -55,7 +55,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
glfwIconifyWindow(window);
|
glfwIconifyWindow(window);
|
||||||
break;
|
break;
|
||||||
case GLFW_KEY_ESCAPE:
|
case GLFW_KEY_ESCAPE:
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (mode == GLFW_FULLSCREEN)
|
if (mode == GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
GLFWvidmode mode;
|
GLFWvidmode desktop_mode;
|
||||||
glfwGetDesktopMode(&mode);
|
glfwGetDesktopMode(&desktop_mode);
|
||||||
width = mode.width;
|
width = desktop_mode.width;
|
||||||
height = mode.height;
|
height = desktop_mode.height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -111,7 +111,7 @@ int main(int argc, char** argv)
|
||||||
height = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(width, height, mode, "Iconify", NULL);
|
window = glfwCreateWindow(width, height, mode, "Iconify", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -120,16 +120,16 @@ int main(int argc, char** argv)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSetWindowSizeCallback(size_callback);
|
glfwSetWindowSizeCallback(size_callback);
|
||||||
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
int width, height;
|
|
||||||
|
|
||||||
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
|
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
|
||||||
active != glfwGetWindowParam(window, GLFW_ACTIVE))
|
active != glfwGetWindowParam(window, GLFW_ACTIVE))
|
||||||
{
|
{
|
||||||
|
@ -152,7 +152,7 @@ int main(int argc, char** argv)
|
||||||
glClearColor(1, 1, 1, 0);
|
glClearColor(1, 1, 1, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ typedef struct Joystick
|
||||||
} Joystick;
|
} Joystick;
|
||||||
|
|
||||||
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
|
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
|
||||||
|
|
||||||
static int joystick_count = 0;
|
static int joystick_count = 0;
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
|
@ -187,7 +186,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -197,16 +196,18 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
refresh_joysticks();
|
refresh_joysticks();
|
||||||
draw_joysticks();
|
draw_joysticks();
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,11 @@ static const char* format_mode(GLFWvidmode* mode)
|
||||||
{
|
{
|
||||||
static char buffer[512];
|
static char buffer[512];
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer),
|
sprintf(buffer,
|
||||||
"%i x %i x %i (%i %i %i)",
|
"%i x %i x %i (%i %i %i)",
|
||||||
mode->width, mode->height,
|
mode->width, mode->height,
|
||||||
mode->redBits + mode->greenBits + mode->blueBits,
|
mode->redBits + mode->greenBits + mode->blueBits,
|
||||||
mode->redBits, mode->greenBits, mode->blueBits);
|
mode->redBits, mode->greenBits, mode->blueBits);
|
||||||
|
|
||||||
buffer[sizeof(buffer) - 1] = '\0';
|
buffer[sizeof(buffer) - 1] = '\0';
|
||||||
return buffer;
|
return buffer;
|
||||||
|
@ -68,7 +68,7 @@ static void error_callback(int error, const char* description)
|
||||||
fprintf(stderr, "Error: %s\n", description);
|
fprintf(stderr, "Error: %s\n", description);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
static void window_size_callback(GLFWwindow in_window, int width, int height)
|
||||||
{
|
{
|
||||||
printf("Window resized to %ix%i\n", width, height);
|
printf("Window resized to %ix%i\n", width, height);
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ static void key_callback(GLFWwindow dummy, int key, int action)
|
||||||
{
|
{
|
||||||
if (key == GLFW_KEY_ESCAPE)
|
if (key == GLFW_KEY_ESCAPE)
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
window = NULL;
|
window = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ static void list_modes(GLFWmonitor monitor)
|
||||||
|
|
||||||
static void test_modes(GLFWmonitor monitor)
|
static void test_modes(GLFWmonitor monitor)
|
||||||
{
|
{
|
||||||
int i, count, width, height;
|
int i, count;
|
||||||
GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
@ -127,19 +127,20 @@ static void test_modes(GLFWmonitor monitor)
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
GLFWvidmode* mode = modes + i;
|
GLFWvidmode* mode = modes + i;
|
||||||
|
GLFWvidmode current;
|
||||||
|
|
||||||
glfwOpenWindowHint(GLFW_RED_BITS, mode->redBits);
|
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
||||||
glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
||||||
glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
||||||
|
|
||||||
printf("Testing mode %u on monitor %s: %s\n",
|
printf("Testing mode %u on monitor %s: %s\n",
|
||||||
(unsigned int) i,
|
(unsigned int) i,
|
||||||
glfwGetMonitorString(monitor, GLFW_MONITOR_NAME),
|
glfwGetMonitorString(monitor, GLFW_MONITOR_NAME),
|
||||||
format_mode(mode));
|
format_mode(mode));
|
||||||
|
|
||||||
window = glfwOpenWindow(mode->width, mode->height,
|
window = glfwCreateWindow(mode->width, mode->height,
|
||||||
GLFW_FULLSCREEN, "Video Mode Test",
|
GLFW_FULLSCREEN, "Video Mode Test",
|
||||||
NULL);
|
NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
printf("Failed to enter mode %u: %s\n",
|
printf("Failed to enter mode %u: %s\n",
|
||||||
|
@ -148,13 +149,15 @@ static void test_modes(GLFWmonitor monitor)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetTime(0.0);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
glfwSetTime(0.0);
|
||||||
|
|
||||||
while (glfwGetTime() < 5.0)
|
while (glfwGetTime() < 5.0)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
if (!window)
|
if (!window)
|
||||||
|
@ -164,31 +167,31 @@ static void test_modes(GLFWmonitor monitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetWindowParam(window, GLFW_RED_BITS) != mode->redBits ||
|
glGetIntegerv(GL_RED_BITS, ¤t.redBits);
|
||||||
glfwGetWindowParam(window, GLFW_GREEN_BITS) != mode->greenBits ||
|
glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits);
|
||||||
glfwGetWindowParam(window, GLFW_BLUE_BITS) != mode->blueBits)
|
glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits);
|
||||||
|
|
||||||
|
glfwGetWindowSize(window, ¤t.width, ¤t.height);
|
||||||
|
|
||||||
|
if (current.redBits != mode->redBits ||
|
||||||
|
current.greenBits != mode->greenBits ||
|
||||||
|
current.blueBits != mode->blueBits)
|
||||||
{
|
{
|
||||||
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
|
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
|
||||||
glfwGetWindowParam(window, GLFW_RED_BITS),
|
current.redBits, current.greenBits, current.blueBits,
|
||||||
glfwGetWindowParam(window, GLFW_GREEN_BITS),
|
mode->redBits, mode->greenBits, mode->blueBits);
|
||||||
glfwGetWindowParam(window, GLFW_BLUE_BITS),
|
|
||||||
mode->redBits,
|
|
||||||
mode->greenBits,
|
|
||||||
mode->blueBits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
if (current.width != mode->width || current.height != mode->height)
|
||||||
|
|
||||||
if (width != mode->width || height != mode->height)
|
|
||||||
{
|
{
|
||||||
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
|
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
|
||||||
width, height,
|
current.width, current.height,
|
||||||
mode->width, mode->height);
|
mode->width, mode->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Closing window\n");
|
printf("Closing window\n");
|
||||||
|
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
window = NULL;
|
window = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
open_window();
|
open_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,17 +94,19 @@ static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
|
|
||||||
static GLboolean open_window(void)
|
static GLboolean open_window(void)
|
||||||
{
|
{
|
||||||
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
|
window_handle = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
|
||||||
if (!window_handle)
|
if (!window_handle)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window_handle);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
|
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
|
||||||
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
|
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetCursorPosCallback(cursor_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -127,11 +129,11 @@ int main(void)
|
||||||
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
|
|
||||||
while (glfwIsWindow(window_handle))
|
while (!glfwGetWindowParam(window_handle, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window_handle);
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,17 +92,19 @@ static GLboolean open_window(int width, int height, int mode)
|
||||||
|
|
||||||
base = glfwGetTime();
|
base = glfwGetTime();
|
||||||
|
|
||||||
window_handle = glfwOpenWindow(width, height, mode, "Window Re-opener", NULL);
|
window_handle = glfwCreateWindow(width, height, mode, "Window Re-opener", NULL);
|
||||||
if (!window_handle)
|
if (!window_handle)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
|
fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window_handle);
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window_close_callback);
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
|
||||||
|
|
||||||
printf("Opening %s mode window took %0.3f seconds\n",
|
printf("Opening %s mode window took %0.3f seconds\n",
|
||||||
get_mode_name(mode),
|
get_mode_name(mode),
|
||||||
|
@ -115,7 +117,7 @@ static void close_window(void)
|
||||||
{
|
{
|
||||||
double base = glfwGetTime();
|
double base = glfwGetTime();
|
||||||
|
|
||||||
glfwCloseWindow(window_handle);
|
glfwDestroyWindow(window_handle);
|
||||||
window_handle = NULL;
|
window_handle = NULL;
|
||||||
|
|
||||||
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
|
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
|
||||||
|
@ -147,7 +149,7 @@ int main(int argc, char** argv)
|
||||||
glRectf(-0.5f, -0.5f, 1.f, 1.f);
|
glRectf(-0.5f, -0.5f, 1.f, 1.f);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window_handle);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
if (closed)
|
if (closed)
|
||||||
|
|
|
@ -36,23 +36,44 @@
|
||||||
#define WIDTH 400
|
#define WIDTH 400
|
||||||
#define HEIGHT 400
|
#define HEIGHT 400
|
||||||
|
|
||||||
|
static GLFWwindow windows[2];
|
||||||
|
|
||||||
static void key_callback(GLFWwindow window, int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
||||||
glfwCloseWindow(window);
|
glfwDestroyWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int window_close_callback(GLFWwindow window)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
if (windows[i] == window)
|
||||||
|
{
|
||||||
|
windows[i] = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLFWwindow open_window(const char* title, GLFWwindow share)
|
static GLFWwindow open_window(const char* title, GLFWwindow share)
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
|
||||||
window = glfwOpenWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share);
|
window = glfwCreateWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share);
|
||||||
if (!window)
|
if (!window)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
glfwSetWindowCloseCallback(window_close_callback);
|
||||||
|
glfwSetKeyCallback(key_callback);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +133,6 @@ static void draw_quad(GLuint texture)
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GLFWwindow windows[2];
|
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
|
@ -150,15 +170,16 @@ int main(int argc, char** argv)
|
||||||
glfwGetWindowPos(windows[0], &x, &y);
|
glfwGetWindowPos(windows[0], &x, &y);
|
||||||
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
|
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
|
||||||
|
|
||||||
while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1]))
|
while (windows[0] && windows[1])
|
||||||
{
|
{
|
||||||
glfwMakeContextCurrent(windows[0]);
|
glfwMakeContextCurrent(windows[0]);
|
||||||
draw_quad(texture);
|
draw_quad(texture);
|
||||||
glfwSwapBuffers();
|
|
||||||
|
|
||||||
glfwMakeContextCurrent(windows[1]);
|
glfwMakeContextCurrent(windows[1]);
|
||||||
draw_quad(texture);
|
draw_quad(texture);
|
||||||
glfwSwapBuffers();
|
|
||||||
|
glfwSwapBuffers(windows[0]);
|
||||||
|
glfwSwapBuffers(windows[1]);
|
||||||
|
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,15 +36,16 @@
|
||||||
|
|
||||||
static int swap_interval;
|
static int swap_interval;
|
||||||
|
|
||||||
static void set_swap_interval(int value)
|
static void set_swap_interval(GLFWwindow window, int interval)
|
||||||
{
|
{
|
||||||
char title[256];
|
char title[256];
|
||||||
|
|
||||||
swap_interval = value;
|
swap_interval = interval;
|
||||||
glfwSwapInterval(swap_interval);
|
glfwSwapInterval(swap_interval);
|
||||||
|
|
||||||
sprintf(title, "Tearing detector (interval %i)", swap_interval);
|
sprintf(title, "Tearing detector (interval %i)", swap_interval);
|
||||||
glfwSetWindowTitle(glfwGetCurrentContext(), title);
|
|
||||||
|
glfwSetWindowTitle(window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
|
@ -55,7 +56,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
static void key_callback(GLFWwindow window, int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||||
set_swap_interval(!swap_interval);
|
set_swap_interval(window, 1 - swap_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -69,7 +70,7 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -78,7 +79,8 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_swap_interval(1);
|
glfwMakeContextCurrent(window);
|
||||||
|
set_swap_interval(window, swap_interval);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
|
@ -87,14 +89,14 @@ int main(void)
|
||||||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
while (glfwIsWindow(window) == GL_TRUE)
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
position = cosf(glfwGetTime() * 4.f) * 0.75f;
|
position = cosf(glfwGetTime() * 4.f) * 0.75f;
|
||||||
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
|
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
|
||||||
|
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,21 +47,22 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
|
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
|
|
||||||
while (glfwIsWindow(window) == GL_TRUE)
|
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(window);
|
||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ int main(void)
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
windows[i] = glfwOpenWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
|
windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
|
||||||
if (!windows[i])
|
if (!windows[i])
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open GLFW window: %s\n",
|
fprintf(stderr, "Failed to open GLFW window: %s\n",
|
||||||
|
@ -64,12 +64,13 @@ int main(void)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
|
glfwMakeContextCurrent(windows[i]);
|
||||||
|
|
||||||
glClearColor((GLclampf) (i & 1),
|
glClearColor((GLclampf) (i & 1),
|
||||||
(GLclampf) (i >> 1),
|
(GLclampf) (i >> 1),
|
||||||
i ? 0.0 : 1.0,
|
i ? 0.f : 1.f,
|
||||||
0.0);
|
0.f);
|
||||||
|
|
||||||
|
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
|
@ -78,16 +79,13 @@ int main(void)
|
||||||
{
|
{
|
||||||
glfwMakeContextCurrent(windows[i]);
|
glfwMakeContextCurrent(windows[i]);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers();
|
glfwSwapBuffers(windows[i]);
|
||||||
|
|
||||||
|
if (glfwGetWindowParam(windows[i], GLFW_CLOSE_REQUESTED))
|
||||||
|
running = GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
if (!glfwIsWindow(windows[i]))
|
|
||||||
running = GL_FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user