Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

quadric.c 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. static 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. static 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. gluDeleteQuadric(qobj);
  106. }
  107. static void display(void)
  108. {
  109. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  110. glPushMatrix();
  111. glEnable(GL_LIGHTING);
  112. glShadeModel (GL_SMOOTH);
  113. glTranslatef(-1.0, -1.0, 0.0);
  114. glCallList(startList);
  115. glShadeModel (GL_FLAT);
  116. glTranslatef(0.0, 2.0, 0.0);
  117. glPushMatrix();
  118. glRotatef(300.0, 1.0, 0.0, 0.0);
  119. glCallList(startList+1);
  120. glPopMatrix();
  121. glDisable(GL_LIGHTING);
  122. glColor3f(0.0, 1.0, 1.0);
  123. glTranslatef(2.0, -2.0, 0.0);
  124. glCallList(startList+2);
  125. glColor3f(1.0, 1.0, 0.0);
  126. glTranslatef(0.0, 2.0, 0.0);
  127. glCallList(startList+3);
  128. glPopMatrix();
  129. glFlush();
  130. }
  131. static void reshape (int w, int h)
  132. {
  133. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  134. glMatrixMode(GL_PROJECTION);
  135. glLoadIdentity();
  136. if (w <= h)
  137. glOrtho(-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w,
  138. 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
  139. else
  140. glOrtho(-2.5*(GLfloat)w/(GLfloat)h,
  141. 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0);
  142. glMatrixMode(GL_MODELVIEW);
  143. glLoadIdentity();
  144. }
  145. /* ARGSUSED1 */
  146. static void keyboard(unsigned char key, int x, int y)
  147. {
  148. switch (key) {
  149. case 27:
  150. exit(0);
  151. break;
  152. }
  153. }
  154. int main(int argc, char** argv)
  155. {
  156. glutInit(&argc, argv);
  157. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  158. glutInitWindowSize(500, 500);
  159. glutInitWindowPosition(100, 100);
  160. glutCreateWindow(argv[0]);
  161. init();
  162. glutDisplayFunc(display);
  163. glutReshapeFunc(reshape);
  164. glutKeyboardFunc(keyboard);
  165. glutMainLoop();
  166. return 0;
  167. }