Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Copyright (c) Mark J. Kilgard, 1994. */
  2. /**
  3. * (c) Copyright 1993, Silicon Graphics, Inc.
  4. * ALL RIGHTS RESERVED
  5. * Permission to use, copy, modify, and distribute this software for
  6. * any purpose and without fee is hereby granted, provided that the above
  7. * copyright notice appear in all copies and that both the copyright notice
  8. * and this permission notice appear in supporting documentation, and that
  9. * the name of Silicon Graphics, Inc. not be used in advertising
  10. * or publicity pertaining to distribution of the software without specific,
  11. * written prior permission.
  12. *
  13. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  22. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25. *
  26. * US Government Users Restricted Rights
  27. * Use, duplication, or disclosure by the Government is subject to
  28. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30. * clause at DFARS 252.227-7013 and/or in similar or successor
  31. * clauses in the FAR or the DOD or NASA FAR Supplement.
  32. * Unpublished-- rights reserved under the copyright laws of the
  33. * United States. Contractor/manufacturer is Silicon Graphics,
  34. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  35. *
  36. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37. */
  38. /**
  39. * teapots.c
  40. * This program demonstrates lots of material properties.
  41. * A single light source illuminates the objects.
  42. */
  43. #include <stdlib.h>
  44. #include <GL/glut.h>
  45. /*
  46. * Initialize depth buffer, projection matrix, light source, and lighting
  47. * model. Do not specify a material property here.
  48. */
  49. void
  50. myinit(void)
  51. {
  52. GLfloat ambient[] =
  53. {0.0, 0.0, 0.0, 1.0};
  54. GLfloat diffuse[] =
  55. {1.0, 1.0, 1.0, 1.0};
  56. GLfloat position[] =
  57. {0.0, 3.0, 3.0, 0.0};
  58. GLfloat lmodel_ambient[] =
  59. {0.2, 0.2, 0.2, 1.0};
  60. GLfloat local_view[] =
  61. {0.0};
  62. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  63. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  64. glLightfv(GL_LIGHT0, GL_POSITION, position);
  65. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  66. glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
  67. glFrontFace(GL_CW);
  68. glEnable(GL_LIGHTING);
  69. glEnable(GL_LIGHT0);
  70. glEnable(GL_AUTO_NORMAL);
  71. glEnable(GL_NORMALIZE);
  72. glEnable(GL_DEPTH_TEST);
  73. glDepthFunc(GL_LESS);
  74. }
  75. /*
  76. * Move object into position. Use 3rd through 12th parameters to specify the
  77. * material property. Draw a teapot.
  78. */
  79. void
  80. renderTeapot(GLfloat x, GLfloat y,
  81. GLfloat ambr, GLfloat ambg, GLfloat ambb,
  82. GLfloat difr, GLfloat difg, GLfloat difb,
  83. GLfloat specr, GLfloat specg, GLfloat specb, GLfloat shine)
  84. {
  85. float mat[4];
  86. glPushMatrix();
  87. glTranslatef(x, y, 0.0);
  88. mat[0] = ambr;
  89. mat[1] = ambg;
  90. mat[2] = ambb;
  91. mat[3] = 1.0;
  92. glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
  93. mat[0] = difr;
  94. mat[1] = difg;
  95. mat[2] = difb;
  96. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
  97. mat[0] = specr;
  98. mat[1] = specg;
  99. mat[2] = specb;
  100. glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
  101. glMaterialf(GL_FRONT, GL_SHININESS, shine * 128.0);
  102. glutSolidTeapot(1.0);
  103. glPopMatrix();
  104. }
  105. /**
  106. * First column: emerald, jade, obsidian, pearl, ruby, turquoise
  107. * 2nd column: brass, bronze, chrome, copper, gold, silver
  108. * 3rd column: black, cyan, green, red, white, yellow plastic
  109. * 4th column: black, cyan, green, red, white, yellow rubber
  110. */
  111. void
  112. display(void)
  113. {
  114. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  115. renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215,
  116. 0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6);
  117. renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575,
  118. 0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1);
  119. renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625,
  120. 0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3);
  121. renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725,
  122. 1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088);
  123. renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175,
  124. 0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6);
  125. renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745,
  126. 0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1);
  127. renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451,
  128. 0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
  129. 0.21794872);
  130. renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054,
  131. 0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2);
  132. renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25,
  133. 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6);
  134. renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225,
  135. 0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1);
  136. renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745,
  137. 0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4);
  138. renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225,
  139. 0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4);
  140. renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
  141. 0.50, 0.50, 0.50, .25);
  142. renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
  143. 0.50196078, 0.50196078, 0.50196078, .25);
  144. renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0,
  145. 0.1, 0.35, 0.1, 0.45, 0.55, 0.45, .25);
  146. renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
  147. 0.7, 0.6, 0.6, .25);
  148. renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
  149. 0.70, 0.70, 0.70, .25);
  150. renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
  151. 0.60, 0.60, 0.50, .25);
  152. renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
  153. 0.4, 0.4, 0.4, .078125);
  154. renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
  155. 0.04, 0.7, 0.7, .078125);
  156. renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
  157. 0.04, 0.7, 0.04, .078125);
  158. renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
  159. 0.7, 0.04, 0.04, .078125);
  160. renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
  161. 0.7, 0.7, 0.7, .078125);
  162. renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
  163. 0.7, 0.7, 0.04, .078125);
  164. glFlush();
  165. }
  166. void
  167. myReshape(int w, int h)
  168. {
  169. glViewport(0, 0, w, h);
  170. glMatrixMode(GL_PROJECTION);
  171. glLoadIdentity();
  172. if (w <= h)
  173. glOrtho(0.0, 16.0, 0.0, 16.0 * (GLfloat) h / (GLfloat) w,
  174. -10.0, 10.0);
  175. else
  176. glOrtho(0.0, 16.0 * (GLfloat) w / (GLfloat) h, 0.0, 16.0,
  177. -10.0, 10.0);
  178. glMatrixMode(GL_MODELVIEW);
  179. }
  180. static void
  181. key(unsigned char k, int x, int y)
  182. {
  183. switch (k) {
  184. case 27: /* Escape */
  185. exit(0);
  186. break;
  187. default:
  188. return;
  189. }
  190. glutPostRedisplay();
  191. }
  192. /*
  193. * Main Loop Open window with initial window size, title bar, RGBA display
  194. * mode, and handle input events.
  195. */
  196. int
  197. main(int argc, char **argv)
  198. {
  199. glutInit(&argc, argv);
  200. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  201. glutCreateWindow(argv[0]);
  202. myinit();
  203. glutReshapeFunc(myReshape);
  204. glutDisplayFunc(display);
  205. glutKeyboardFunc(key);
  206. glutMainLoop();
  207. return 0; /* ANSI C requires main to return int. */
  208. }