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

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  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. /* Exercise all the GLUT shapes. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #ifdef _WIN32
  13. #include <windows.h>
  14. #define sleep(x) Sleep(1000 * x)
  15. #else
  16. #include <unistd.h>
  17. #endif
  18. #include <GL/glut.h>
  19.  
  20. GLfloat light_diffuse[] =
  21. {1.0, 0.0, 0.0, 1.0};
  22. GLfloat light_position[] =
  23. {1.0, 1.0, 1.0, 0.0};
  24.  
  25. void
  26. displayFunc(void)
  27. {
  28.   static int shape = 1;
  29.  
  30.   fprintf(stderr, " %d", shape);
  31.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  32.   switch (shape) {
  33.   case 1:
  34.     glutWireSphere(1.0, 20, 20);
  35.     break;
  36.   case 2:
  37.     glutSolidSphere(1.0, 20, 20);
  38.     break;
  39.   case 3:
  40.     glutWireCone(1.0, 1.0, 20, 20);
  41.     break;
  42.   case 4:
  43.     glutSolidCone(1.0, 1.0, 20, 20);
  44.     break;
  45.   case 5:
  46.     glutWireCube(1.0);
  47.     break;
  48.   case 6:
  49.     glutSolidCube(1.0);
  50.     break;
  51.   case 7:
  52.     glutWireTorus(0.5, 1.0, 15, 15);
  53.     break;
  54.   case 8:
  55.     glutSolidTorus(0.5, 1.0, 15, 15);
  56.     break;
  57.   case 9:
  58.     glutWireDodecahedron();
  59.     break;
  60.   case 10:
  61.     glutSolidDodecahedron();
  62.     break;
  63.   case 11:
  64.     glutWireTeapot(1.0);
  65.     break;
  66.   case 12:
  67.     glutSolidTeapot(1.0);
  68.     break;
  69.   case 13:
  70.     glutWireOctahedron();
  71.     break;
  72.   case 14:
  73.     glutSolidOctahedron();
  74.     break;
  75.   case 15:
  76.     glutWireTetrahedron();
  77.     break;
  78.   case 16:
  79.     glutSolidTetrahedron();
  80.     break;
  81.   case 17:
  82.     glutWireIcosahedron();
  83.     break;
  84.   case 18:
  85.     glutSolidIcosahedron();
  86.     break;
  87.   default:
  88.     printf("\nPASS: test16\n");
  89.     exit(0);
  90.   }
  91.   glutSwapBuffers();
  92.   shape += 1;
  93.   sleep(1);
  94.   glutPostRedisplay();
  95. }
  96.  
  97. /* ARGSUSED */
  98. void
  99. timefunc(int value)
  100. {
  101.   printf("\nFAIL: test16\n");
  102.   exit(1);
  103. }
  104.  
  105. int
  106. main(int argc, char **argv)
  107. {
  108.   glutInit(&argc, argv);
  109.   glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
  110.   glutCreateWindow("test16");
  111.   glutDisplayFunc(displayFunc);
  112.  
  113.   glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  114.   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  115.   glEnable(GL_LIGHTING);
  116.   glEnable(GL_LIGHT0);
  117.   glEnable(GL_DEPTH_TEST);
  118.   glMatrixMode(GL_PROJECTION);
  119.   gluPerspective( /* field of view in degree */ 22.0,
  120.   /* aspect ratio */ 1.0,
  121.     /* Z near */ 1.0, /* Z far */ 10.0);
  122.   glMatrixMode(GL_MODELVIEW);
  123.   gluLookAt(0.0, 0.0, 5.0,  /* eye is at (0,0,5) */
  124.     0.0, 0.0, 0.0,      /* center is at (0,0,0) */
  125.     0.0, 1.0, 0.);      /* up is in postivie Y direction */
  126.   glTranslatef(0.0, 0.0, -3.0);
  127.   glRotatef(25, 1.0, 0.0, 0.0);
  128.  
  129.   /* Have a reasonably large timeout since some machines make
  130.      take a while to render all those polygons. */
  131.   glutTimerFunc(35000, timefunc, 1);
  132.  
  133.   fprintf(stderr, "shape =");
  134.   glutMainLoop();
  135.   return 0;             /* ANSI C requires main to return int. */
  136. }
  137.