| 1 | /* |
|---|
| 2 | On Mac, compile with: |
|---|
| 3 | gcc -framework OpenGL -framework GLUT -o tcb-c main.c |
|---|
| 4 | |
|---|
| 5 | Run with: |
|---|
| 6 | ./tcb-c <test> <timeout> |
|---|
| 7 | */ |
|---|
| 8 | #include <stdlib.h> |
|---|
| 9 | #include <stdio.h> |
|---|
| 10 | #include <sys/time.h> |
|---|
| 11 | #include <OpenGL/gl.h> |
|---|
| 12 | #include <OpenGL/glu.h> |
|---|
| 13 | #include <GLUT/glut.h> |
|---|
| 14 | |
|---|
| 15 | GLvoid InitGL(GLvoid) {} |
|---|
| 16 | GLvoid DrawGLScene(GLvoid) {} |
|---|
| 17 | GLvoid ReSizeGLScene(int Width, int Height) {} |
|---|
| 18 | |
|---|
| 19 | int tickLength; |
|---|
| 20 | |
|---|
| 21 | void putTicks (int ticks) { |
|---|
| 22 | struct timeval tv; |
|---|
| 23 | int tod = gettimeofday(&tv, NULL); |
|---|
| 24 | |
|---|
| 25 | if (tod == 0) { |
|---|
| 26 | printf("tick: %2d, %6d%06d\n", ticks, tv.tv_sec, tv.tv_usec); |
|---|
| 27 | } else { |
|---|
| 28 | printf("tick: %2d, Error getting time\n", ticks); |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | void test1 () { |
|---|
| 33 | int ii; |
|---|
| 34 | for (ii = 0; ii < 5; ii++) { |
|---|
| 35 | glutTimerFunc(tickLength * ii, putTicks, ii); |
|---|
| 36 | } |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | void test2 (int ticks) { |
|---|
| 40 | if (ticks > 5) return; |
|---|
| 41 | if (ticks > 0) putTicks(ticks - 1); |
|---|
| 42 | glutTimerFunc(tickLength, test2, ticks + 1); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | int main (int argc, char** argv) { |
|---|
| 46 | if (argc != 3) { |
|---|
| 47 | printf("Need two arguments.\n"); |
|---|
| 48 | exit(-1); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | tickLength = atoi(argv[2]); |
|---|
| 52 | |
|---|
| 53 | glutInit(&argc, argv); |
|---|
| 54 | glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); |
|---|
| 55 | glutInitWindowSize (400, 400); |
|---|
| 56 | glutInitWindowPosition (0, 0); |
|---|
| 57 | glutCreateWindow ("TCB - Bug Test"); |
|---|
| 58 | |
|---|
| 59 | InitGL(); |
|---|
| 60 | |
|---|
| 61 | switch (argv[1][0]) { |
|---|
| 62 | case '1': |
|---|
| 63 | test1(); |
|---|
| 64 | break; |
|---|
| 65 | case '2': |
|---|
| 66 | test2(0); |
|---|
| 67 | break; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | glutDisplayFunc(DrawGLScene); |
|---|
| 71 | glutReshapeFunc(ReSizeGLScene); |
|---|
| 72 | |
|---|
| 73 | glutMainLoop(); |
|---|
| 74 | |
|---|
| 75 | return 0; |
|---|
| 76 | } |
|---|