// Peter Bui // CSE 40166 Computer Graphics (Fall 2010) // Example 1: simple hello, world program #include #ifdef __APPLE__ #include #else #include #endif // Display callback ------------------------------------------------------------ void display() { glClear(GL_COLOR_BUFFER_BIT); // Erase everything glColor3f(0.0, 0.0, 1.0); // Set color blue glBegin(GL_POLYGON); { // Define a polygon glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f( 0.5, 0.5); glVertex2f( 0.5, -0.5); } glEnd(); glFlush(); // Flush all drawings to the screen } // Keyboard callback ------------------------------------------------------------ void keyboard(unsigned char key, int x, int y) { if (key == 'q' || key == 'Q') exit(EXIT_SUCCESS); } // Main execution --------------------------------------------------------------- int main(int argc, char *argv[]) { glutInit(&argc, argv); // Initialize GLUT glutCreateWindow("hello"); // Create a window glutDisplayFunc(display); // Register display callback glutKeyboardFunc(keyboard); // Register keyboard callback glutMainLoop(); // Enter main event loop return (EXIT_SUCCESS); } // vim: sts=4 sw=4 ts=8 ft=cpp