fork download
  1. /*
  2.  * GLUT Shapes Demo
  3.  *
  4.  * Written by Nigel Stewart November 2003
  5.  *
  6.  * This program is test harness for the sphere, cone
  7.  * and torus shapes in GLUT.
  8.  *
  9.  * Spinning wireframe and smooth shaded shapes are
  10.  * displayed until the ESC or q key is pressed. The
  11.  * number of geometry stacks and slices can be adjusted
  12.  * using the + and - keys.
  13.  */
  14.  
  15. #ifdef __APPLE__
  16. #include <GLUT/glut.h>
  17. #else
  18. #include <GL/glut.h>
  19. #endif
  20.  
  21. #include <stdlib.h>
  22.  
  23. static int slices = 16;
  24. static int stacks = 16;
  25.  
  26. /* GLUT callback Handlers */
  27.  
  28. static void resize(int width, int height)
  29. {
  30. const float ar = (float) width / (float) height;
  31.  
  32. glViewport(0, 0, width, height);
  33. glMatrixMode(GL_PROJECTION);
  34. glLoadIdentity();
  35. glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
  36.  
  37. glMatrixMode(GL_MODELVIEW);
  38. glLoadIdentity() ;
  39. }
  40.  
  41. static void display(void)
  42. {
  43. const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
  44. const double a = t*90.0;
  45.  
  46. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  47. glColor3d(1,0,0);
  48.  
  49. glPushMatrix();
  50. glTranslated(-2.4,1.2,-6);
  51. glRotated(60,1,0,0);
  52. glRotated(a,0,0,1);
  53. glutSolidSphere(1,slices,stacks);
  54. glPopMatrix();
  55.  
  56. glPushMatrix();
  57. glTranslated(0,1.2,-6);
  58. glRotated(60,1,0,0);
  59. glRotated(a,0,0,1);
  60. glutSolidCone(1,1,slices,stacks);
  61. glPopMatrix();
  62.  
  63. glPushMatrix();
  64. glTranslated(2.4,1.2,-6);
  65. glRotated(60,1,0,0);
  66. glRotated(a,0,0,1);
  67. glutSolidTorus(0.2,0.8,slices,stacks);
  68. glPopMatrix();
  69.  
  70. glPushMatrix();
  71. glTranslated(-2.4,-1.2,-6);
  72. glRotated(60,1,0,0);
  73. glRotated(a,0,0,1);
  74. glutWireSphere(1,slices,stacks);
  75. glPopMatrix();
  76.  
  77. glPushMatrix();
  78. glTranslated(0,-1.2,-6);
  79. glRotated(60,1,0,0);
  80. glRotated(a,0,0,1);
  81. glutWireCone(1,1,slices,stacks);
  82. glPopMatrix();
  83.  
  84. glPushMatrix();
  85. glTranslated(2.4,-1.2,-6);
  86. glRotated(60,1,0,0);
  87. glRotated(a,0,0,1);
  88. glutWireTorus(0.2,0.8,slices,stacks);
  89. glPopMatrix();
  90.  
  91. glutSwapBuffers();
  92. }
  93.  
  94.  
  95. static void key(unsigned char key, int x, int y)
  96. {
  97. switch (key)
  98. {
  99. case 27 :
  100. case 'q':
  101. exit(0);
  102. break;
  103.  
  104. case '+':
  105. slices++;
  106. stacks++;
  107. break;
  108.  
  109. case '-':
  110. if (slices>3 && stacks>3)
  111. {
  112. slices--;
  113. stacks--;
  114. }
  115. break;
  116. }
  117.  
  118. glutPostRedisplay();
  119. }
  120.  
  121. static void idle(void)
  122. {
  123. glutPostRedisplay();
  124. }
  125.  
  126. const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
  127. const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  128. const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  129. const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
  130.  
  131. const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
  132. const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
  133. const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  134. const GLfloat high_shininess[] = { 100.0f };
  135.  
  136. /* Program entry point */
  137.  
  138. int main(int argc, char *argv[])
  139. {
  140. glutInit(&argc, argv);
  141. glutInitWindowSize(640,480);
  142. glutInitWindowPosition(10,10);
  143. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  144.  
  145. glutCreateWindow("GLUT Shapes");
  146.  
  147. glutReshapeFunc(resize);
  148. glutDisplayFunc(display);
  149. glutKeyboardFunc(key);
  150. glutIdleFunc(idle);
  151.  
  152. glClearColor(1,1,1,1);
  153. glEnable(GL_CULL_FACE);
  154. glCullFace(GL_BACK);
  155.  
  156. glEnable(GL_DEPTH_TEST);
  157. glDepthFunc(GL_LESS);
  158.  
  159. glEnable(GL_LIGHT0);
  160. glEnable(GL_NORMALIZE);
  161. glEnable(GL_COLOR_MATERIAL);
  162. glEnable(GL_LIGHTING);
  163.  
  164. glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  165. glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  166. glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  167. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  168.  
  169. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  170. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  171. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  172. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  173.  
  174. glutMainLoop();
  175.  
  176. return EXIT_SUCCESS;
  177. }
  178.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:18:21: fatal error: GL/glut.h: No such file or directory
 #include <GL/glut.h>
                     ^
compilation terminated.
stdout
Standard output is empty