#if __APPLE__ #include #else #include #endif #include #include // ----------------------------------------------------------------- int window_width, window_height ; double s = 0.1 ; double delta = 0.01 ; int timer_active = 0 ; int timer_interval = 1000/50 ; // 50 Hz // ----------------------------------------------------------------- void reshape(int width, int height) { window_width = width ; window_height = height ; } void display(void) { glClearColor(1.0,1.0,1.0,1.0) ; glClear(GL_COLOR_BUFFER_BIT) ; glMatrixMode(GL_PROJECTION) ; glLoadIdentity() ; glMatrixMode(GL_MODELVIEW) ; glLoadIdentity() ; glColor3f(0.0,0.0,s) ; glRectf(-s,-s,s,s) ; glutSwapBuffers() ; } void animate(int theTimer) { if (!timer_active) return ; s+=delta ; if (s>=0.5) { s=0.5 ; delta*=-1 ; } if (s<=0.0) { s=0 ; delta*=-1 ; } glutPostRedisplay() ; glutTimerFunc(timer_interval, animate, theTimer) ; } void keyboard(unsigned char key, int x, int y) { switch (key) { case ' ': case 'a': if (!timer_active) glutTimerFunc(timer_interval, animate, 0) ; timer_active = ! timer_active ; break ; case 27: // Escape exit(0) ; } } // ----------------------------------------------------------------- int main(int argc, char *argv[]) { glutInit(&argc, argv) ; glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE) ; glutInitWindowPosition(0, 0) ; glutInitWindowSize(400, 300) ; glutCreateWindow("transform") ; glutReshapeFunc(reshape) ; glutDisplayFunc(display) ; glutKeyboardFunc(keyboard) ; srandom((unsigned int)(time(0)%737)) ; glutMainLoop() ; return 0 ; }