int main( void ) { // Initialise GLFW if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); } // Open OpenGL window if( !glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW ) ) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); exit( EXIT_FAILURE ); } // Enable vsync glfwSwapInterval( 1 ); // Set window title glfwSetWindowTitle( "Split view demo" ); // Enable sticky keys glfwEnable( GLFW_STICKY_KEYS ); // Enable mouse cursor (only needed for fullscreen mode) glfwEnable( GLFW_MOUSE_CURSOR ); // Disable automatic event polling glfwDisable( GLFW_AUTO_POLL_EVENTS ); // Set callback functions glfwSetWindowSizeCallback( windowSizeFun ); glfwSetWindowRefreshCallback( windowRefreshFun ); glfwSetMousePosCallback( mousePosFun ); glfwSetMouseButtonCallback( mouseButtonFun ); // Main loop do { // Only redraw if we need to if( do_redraw ) { // Draw all views drawAllViews(); // Swap buffers glfwSwapBuffers(); do_redraw = 0; } // Wait for new events glfwWaitEvents(); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) ); // Close OpenGL window and terminate GLFW glfwTerminate(); exit( EXIT_SUCCESS ); }
int main(void) { GLFWwindow* window; // Initialise GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); } // Open OpenGL window window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL); if (!window) { fprintf(stderr, "Failed to open GLFW window\n"); glfwTerminate(); exit(EXIT_FAILURE); } // Set callback functions glfwSetWindowSizeCallback(window, windowSizeFun); glfwSetWindowRefreshCallback(window, windowRefreshFun); glfwSetCursorPosCallback(window, cursorPosFun); glfwSetMouseButtonCallback(window, mouseButtonFun); glfwSetKeyCallback(window, key_callback); // Enable vsync glfwMakeContextCurrent(window); glfwSwapInterval(1); glfwGetWindowSize(window, &width, &height); windowSizeFun(window, width, height); // Main loop for (;;) { // Only redraw if we need to if (do_redraw) { // Draw all views drawAllViews(); // Swap buffers glfwSwapBuffers(window); do_redraw = 0; } // Wait for new events glfwWaitEvents(); // Check if the window should be closed if (glfwWindowShouldClose(window)) break; } // Close OpenGL window and terminate GLFW glfwTerminate(); exit(EXIT_SUCCESS); }
static void windowRefreshFun(GLFWwindow* window) { drawAllViews(); glfwSwapBuffers(window); do_redraw = 0; }