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