3 * Written by John Tsiombikas <nuclear@member.fsf.org>
5 * Demonstrate the use of glutTimerFunc, by changing the color of the
6 * framebuffer every (approximately) 1 sec.
12 void timer_func(int unused);
14 /* color index will be advanced every time the timer expires */
26 int main(int argc, char **argv)
28 glutInit(&argc, argv);
29 glutInitWindowSize(128, 128);
30 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
31 glutCreateWindow("timer test");
33 glutDisplayFunc(disp);
35 /* get timer started, its reset in the timer function itself */
36 glutTimerFunc(1000, timer_func, 1);
37 glutTimerFunc(500, timer_func, 2);
45 glClearColor(color[cidx][0], color[cidx][1], color[cidx][2], 1);
46 glClear(GL_COLOR_BUFFER_BIT);
49 glColor3f(color[pcidx][0], color[pcidx][1], color[pcidx][2]);
57 void timer_func(int which)
59 /* advance the color index and trigger a redisplay */
63 cidx = (cidx + 1) % (sizeof color / sizeof *color);
66 pcidx = (pcidx + 1) % (sizeof color / sizeof *color);
72 /* (re)set the timer callback and ask glut to call it in 1 second */
73 glutTimerFunc(1000, timer_func, which);