home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / sviluppo / mesa-glut / test / glut / timer_test.c < prev   
C/C++ Source or Header  |  1998-10-08  |  2KB  |  69 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1996. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. /* timer_test is supposed to demonstrate that window system
  9.    event related callbacks (like the keyboard callback) do not
  10.    "starve out" the dispatching of timer callbacks.  Run this
  11.    program and hold down the space bar.  The correct behavior
  12.    (assuming the system does autorepeat) is interleaved "key is 
  13.    32" and "timer called" messages.  If you don't see "timer
  14.    called" messages, that's a problem.  This problem exists in
  15.    GLUT implementations through GLUT 3.2. */
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19.  
  20. #ifdef _WIN32
  21. #include <windows.h>
  22. #define sleep(x) Sleep(1000 * x)
  23. #else
  24. #include <unistd.h>
  25. #endif
  26.  
  27. #include <GL/glut.h>
  28.  
  29. void
  30. display(void)
  31. {
  32.   glClear(GL_COLOR_BUFFER_BIT);
  33.   glFlush();
  34. }
  35.  
  36. /* ARGSUSED */
  37. void
  38. timer(int value)
  39. {
  40.   printf("timer called\n");
  41.   glutTimerFunc(500, timer, 0);
  42. }
  43.  
  44. /* ARGSUSED1 */
  45. void
  46. keyboard(unsigned char k, int x, int y)
  47. {
  48.   static int beenhere = 0;
  49.  
  50.   if (!beenhere) {
  51.     glutTimerFunc(500, timer, 0);
  52.     beenhere = 1;
  53.   }
  54.   printf("key is %d\n", k);
  55.   sleep(1);
  56. }
  57.  
  58. int
  59. main(int argc, char **argv)
  60. {
  61.   glutInit(&argc, argv);
  62.   glutCreateWindow("timer test");
  63.   glClearColor(0.49, 0.62, 0.75, 0.0);
  64.   glutDisplayFunc(display);
  65.   glutKeyboardFunc(keyboard);
  66.   glutMainLoop();
  67.   return 0;             /* ANSI C requires main to return int. */
  68. }
  69.