Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

quadric.c 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (c) 1993-1997, Silicon Graphics, Inc.
  3. * ALL RIGHTS RESERVED
  4. * Permission to use, copy, modify, and distribute this software for
  5. * any purpose and without fee is hereby granted, provided that the above
  6. * copyright notice appear in all copies and that both the copyright notice
  7. * and this permission notice appear in supporting documentation, and that
  8. * the name of Silicon Graphics, Inc. not be used in advertising
  9. * or publicity pertaining to distribution of the software without specific,
  10. * written prior permission.
  11. *
  12. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  16. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  21. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. * US Government Users Restricted Rights
  26. * Use, duplication, or disclosure by the Government is subject to
  27. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. * clause at DFARS 252.227-7013 and/or in similar or successor
  30. * clauses in the FAR or the DOD or NASA FAR Supplement.
  31. * Unpublished-- rights reserved under the copyright laws of the
  32. * United States. Contractor/manufacturer is Silicon Graphics,
  33. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  34. *
  35. * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
  36. */
  37. /*
  38. * quadric.c
  39. * This program demonstrates the use of some of the gluQuadric*
  40. * routines. Quadric objects are created with some quadric
  41. * properties and the callback routine to handle errors.
  42. * Note that the cylinder has no top or bottom and the circle
  43. * has a hole in it.
  44. */
  45. #include <GL/glut.h>
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. /* Win32 calling conventions. */
  49. #ifndef CALLBACK
  50. #define CALLBACK
  51. #endif
  52. GLuint startList;
  53. void CALLBACK errorCallback(GLenum errorCode)
  54. {
  55. const GLubyte *estring;
  56. estring = gluErrorString(errorCode);
  57. fprintf(stderr, "Quadric Error: %s\n", estring);
  58. exit(0);
  59. }
  60. void init(void)
  61. {
  62. GLUquadricObj *qobj;
  63. GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
  64. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  65. GLfloat mat_shininess[] = { 50.0 };
  66. GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
  67. GLfloat model_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
  68. glClearColor(0.0, 0.0, 0.0, 0.0);
  69. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  70. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  71. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  72. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  73. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
  74. glEnable(GL_LIGHTING);
  75. glEnable(GL_LIGHT0);
  76. glEnable(GL_DEPTH_TEST);
  77. /* Create 4 display lists, each with a different quadric object.
  78. * Different drawing styles and surface normal specifications
  79. * are demonstrated.
  80. */
  81. startList = glGenLists(4);
  82. qobj = gluNewQuadric();
  83. gluQuadricCallback(qobj, GLU_ERROR,
  84. (GLvoid (CALLBACK*) ()) errorCallback);
  85. gluQuadricDrawStyle(qobj, GLU_FILL); /* smooth shaded */
  86. gluQuadricNormals(qobj, GLU_SMOOTH);
  87. glNewList(startList, GL_COMPILE);
  88. gluSphere(qobj, 0.75, 15, 10);
  89. glEndList();
  90. gluQuadricDrawStyle(qobj, GLU_FILL); /* flat shaded */
  91. gluQuadricNormals(qobj, GLU_FLAT);
  92. glNewList(startList+1, GL_COMPILE);
  93. gluCylinder(qobj, 0.5, 0.3, 1.0, 15, 5);
  94. glEndList();
  95. gluQuadricDrawStyle(qobj, GLU_LINE); /* all polygons wireframe */
  96. gluQuadricNormals(qobj, GLU_NONE);
  97. glNewList(startList+2, GL_COMPILE);
  98. gluDisk(qobj, 0.25, 1.0, 20, 4);
  99. glEndList();
  100. gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); /* boundary only */
  101. gluQuadricNormals(qobj, GLU_NONE);
  102. glNewList(startList+3, GL_COMPILE);
  103. gluPartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0);
  104. glEndList();
  105. }
  106. void display(void)
  107. {
  108. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  109. glPushMatrix();
  110. glEnable(GL_LIGHTING);
  111. glShadeModel (GL_SMOOTH);
  112. glTranslatef(-1.0, -1.0, 0.0);
  113. glCallList(startList);
  114. glShadeModel (GL_FLAT);
  115. glTranslatef(0.0, 2.0, 0.0);
  116. glPushMatrix();
  117. glRotatef(300.0, 1.0, 0.0, 0.0);
  118. glCallList(startList+1);
  119. glPopMatrix();
  120. glDisable(GL_LIGHTING);
  121. glColor3f(0.0, 1.0, 1.0);
  122. glTranslatef(2.0, -2.0, 0.0);
  123. glCallList(startList+2);
  124. glColor3f(1.0, 1.0, 0.0);
  125. glTranslatef(0.0, 2.0, 0.0);
  126. glCallList(startList+3);
  127. glPopMatrix();
  128. glFlush();
  129. }
  130. void reshape (int w, int h)
  131. {
  132. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  133. glMatrixMode(GL_PROJECTION);
  134. glLoadIdentity();
  135. if (w <= h)
  136. glOrtho(-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w,
  137. 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
  138. else
  139. glOrtho(-2.5*(GLfloat)w/(GLfloat)h,
  140. 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0);
  141. glMatrixMode(GL_MODELVIEW);
  142. glLoadIdentity();
  143. }
  144. /* ARGSUSED1 */
  145. void keyboard(unsigned char key, int x, int y)
  146. {
  147. switch (key) {
  148. case 27:
  149. exit(0);
  150. break;
  151. }
  152. }
  153. int main(int argc, char** argv)
  154. {
  155. glutInit(&argc, argv);
  156. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  157. glutInitWindowSize(500, 500);
  158. glutInitWindowPosition(100, 100);
  159. glutCreateWindow(argv[0]);
  160. init();
  161. glutDisplayFunc(display);
  162. glutReshapeFunc(reshape);
  163. glutKeyboardFunc(keyboard);
  164. glutMainLoop();
  165. return 0;
  166. }