Source code of Windows XP (NT5)
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.

290 lines
11 KiB

  1. /*
  2. * (c) Copyright 1993, 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(TM) is a trademark of Silicon Graphics, Inc.
  36. */
  37. /*
  38. * material.c
  39. * This program demonstrates the use of the GL lighting model.
  40. * Several objects are drawn using different material characteristics.
  41. * A single light source illuminates the objects.
  42. */
  43. #include <windows.h>
  44. #include <GL/gl.h>
  45. #include <GL/glu.h>
  46. #include "glaux.h"
  47. /* Initialize z-buffer, projection matrix, light source,
  48. * and lighting model. Do not specify a material property here.
  49. */
  50. void myinit(void)
  51. {
  52. GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
  53. GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
  54. GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
  55. GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
  56. GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
  57. GLfloat local_view[] = { 0.0 };
  58. glEnable(GL_DEPTH_TEST);
  59. glDepthFunc(GL_LESS);
  60. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  61. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  62. glLightfv(GL_LIGHT0, GL_POSITION, position);
  63. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  64. glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
  65. glEnable(GL_LIGHTING);
  66. glEnable(GL_LIGHT0);
  67. glClearColor(0.0, 0.1, 0.1, 0.0);
  68. }
  69. /* Draw twelve spheres in 3 rows with 4 columns.
  70. * The spheres in the first row have materials with no ambient reflection.
  71. * The second row has materials with significant ambient reflection.
  72. * The third row has materials with colored ambient reflection.
  73. *
  74. * The first column has materials with blue, diffuse reflection only.
  75. * The second column has blue diffuse reflection, as well as specular
  76. * reflection with a low shininess exponent.
  77. * The third column has blue diffuse reflection, as well as specular
  78. * reflection with a high shininess exponent (a more concentrated highlight).
  79. * The fourth column has materials which also include an emissive component.
  80. *
  81. * glTranslatef() is used to move spheres to their appropriate locations.
  82. */
  83. void display(void)
  84. {
  85. GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
  86. GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
  87. GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
  88. GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
  89. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  90. GLfloat no_shininess[] = { 0.0 };
  91. GLfloat low_shininess[] = { 5.0 };
  92. GLfloat high_shininess[] = { 100.0 };
  93. GLfloat mat_emission[] = {0.3, 0.2, 0.2, 0.0};
  94. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  95. /* draw sphere in first row, first column
  96. * diffuse reflection only; no ambient or specular
  97. */
  98. glPushMatrix();
  99. glTranslatef (-3.75, 3.0, 0.0);
  100. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
  101. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  102. glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
  103. glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
  104. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  105. auxSolidSphere(1.0);
  106. glPopMatrix();
  107. /* draw sphere in first row, second column
  108. * diffuse and specular reflection; low shininess; no ambient
  109. */
  110. glPushMatrix();
  111. glTranslatef (-1.25, 3.0, 0.0);
  112. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
  113. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  114. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  115. glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
  116. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  117. auxSolidSphere(1.0);
  118. glPopMatrix();
  119. /* draw sphere in first row, third column
  120. * diffuse and specular reflection; high shininess; no ambient
  121. */
  122. glPushMatrix();
  123. glTranslatef (1.25, 3.0, 0.0);
  124. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
  125. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  126. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  127. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  128. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  129. auxSolidSphere(1.0);
  130. glPopMatrix();
  131. /* draw sphere in first row, fourth column
  132. * diffuse reflection; emission; no ambient or specular reflection
  133. */
  134. glPushMatrix();
  135. glTranslatef (3.75, 3.0, 0.0);
  136. glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
  137. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  138. glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
  139. glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
  140. glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
  141. auxSolidSphere(1.0);
  142. glPopMatrix();
  143. /* draw sphere in second row, first column
  144. * ambient and diffuse reflection; no specular
  145. */
  146. glPushMatrix();
  147. glTranslatef (-3.75, 0.0, 0.0);
  148. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  149. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  150. glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
  151. glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
  152. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  153. auxSolidSphere(1.0);
  154. glPopMatrix();
  155. /* draw sphere in second row, second column
  156. * ambient, diffuse and specular reflection; low shininess
  157. */
  158. glPushMatrix();
  159. glTranslatef (-1.25, 0.0, 0.0);
  160. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  161. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  162. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  163. glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
  164. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  165. auxSolidSphere(1.0);
  166. glPopMatrix();
  167. /* draw sphere in second row, third column
  168. * ambient, diffuse and specular reflection; high shininess
  169. */
  170. glPushMatrix();
  171. glTranslatef (1.25, 0.0, 0.0);
  172. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  173. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  174. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  175. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  176. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  177. auxSolidSphere(1.0);
  178. glPopMatrix();
  179. /* draw sphere in second row, fourth column
  180. * ambient and diffuse reflection; emission; no specular
  181. */
  182. glPushMatrix();
  183. glTranslatef (3.75, 0.0, 0.0);
  184. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  185. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  186. glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
  187. glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
  188. glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
  189. auxSolidSphere(1.0);
  190. glPopMatrix();
  191. /* draw sphere in third row, first column
  192. * colored ambient and diffuse reflection; no specular
  193. */
  194. glPushMatrix();
  195. glTranslatef (-3.75, -3.0, 0.0);
  196. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
  197. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  198. glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
  199. glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
  200. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  201. auxSolidSphere(1.0);
  202. glPopMatrix();
  203. /* draw sphere in third row, second column
  204. * colored ambient, diffuse and specular reflection; low shininess
  205. */
  206. glPushMatrix();
  207. glTranslatef (-1.25, -3.0, 0.0);
  208. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
  209. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  210. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  211. glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
  212. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  213. auxSolidSphere(1.0);
  214. glPopMatrix();
  215. /* draw sphere in third row, third column
  216. * colored ambient, diffuse and specular reflection; high shininess
  217. */
  218. glPushMatrix();
  219. glTranslatef (1.25, -3.0, 0.0);
  220. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
  221. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  222. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  223. glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
  224. glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  225. auxSolidSphere(1.0);
  226. glPopMatrix();
  227. /* draw sphere in third row, fourth column
  228. * colored ambient and diffuse reflection; emission; no specular
  229. */
  230. glPushMatrix();
  231. glTranslatef (3.75, -3.0, 0.0);
  232. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
  233. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  234. glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
  235. glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
  236. glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
  237. auxSolidSphere(1.0);
  238. glPopMatrix();
  239. glFlush();
  240. }
  241. void myReshape(GLsizei w, GLsizei h)
  242. {
  243. glViewport(0, 0, w, h);
  244. glMatrixMode(GL_PROJECTION);
  245. glLoadIdentity();
  246. if (w <= (h * 2))
  247. glOrtho (-6.0, 6.0, -3.0*((GLfloat)h*2)/(GLfloat)w,
  248. 3.0*((GLfloat)h*2)/(GLfloat)w, -10.0, 10.0);
  249. else
  250. glOrtho (-6.0*(GLfloat)w/((GLfloat)h*2),
  251. 6.0*(GLfloat)w/((GLfloat)h*2), -3.0, 3.0, -10.0, 10.0);
  252. glMatrixMode(GL_MODELVIEW);
  253. }
  254. /* Main Loop
  255. * Open window with initial window size, title bar,
  256. * RGBA display mode, and handle input events.
  257. */
  258. int main(int argc, char** argv)
  259. {
  260. auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH16);
  261. auxInitPosition (0, 0, 600, 450);
  262. auxInitWindow (argv[0]);
  263. myinit();
  264. auxReshapeFunc (myReshape);
  265. auxMainLoop(display);
  266. }