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.

312 lines
7.8 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. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include "tk.h"
  41. GLenum rgb, doubleBuffer, directRender;
  42. double plane[4] = {
  43. 1.0, 0.0, -1.0, 0.0
  44. };
  45. float rotX = 5.0, rotY = -5.0, zTranslate = -65.0;
  46. float fogDensity = 0.02;
  47. GLint cubeList = 1;
  48. float scp[18][3] = {
  49. {
  50. 1.000000, 0.000000, 0.000000
  51. },
  52. {
  53. 1.000000, 0.000000, 5.000000
  54. },
  55. {
  56. 0.707107, 0.707107, 0.000000
  57. },
  58. {
  59. 0.707107, 0.707107, 5.000000
  60. },
  61. {
  62. 0.000000, 1.000000, 0.000000
  63. },
  64. {
  65. 0.000000, 1.000000, 5.000000
  66. },
  67. {
  68. -0.707107, 0.707107, 0.000000
  69. },
  70. {
  71. -0.707107, 0.707107, 5.000000
  72. },
  73. {
  74. -1.000000, 0.000000, 0.000000
  75. },
  76. {
  77. -1.000000, 0.000000, 5.000000
  78. },
  79. {
  80. -0.707107, -0.707107, 0.000000
  81. },
  82. {
  83. -0.707107, -0.707107, 5.000000
  84. },
  85. {
  86. 0.000000, -1.000000, 0.000000
  87. },
  88. {
  89. 0.000000, -1.000000, 5.000000
  90. },
  91. {
  92. 0.707107, -0.707107, 0.000000
  93. },
  94. {
  95. 0.707107, -0.707107, 5.000000
  96. },
  97. {
  98. 1.000000, 0.000000, 0.000000
  99. },
  100. {
  101. 1.000000, 0.000000, 5.000000
  102. },
  103. };
  104. static void Build_lists(void)
  105. {
  106. glNewList(cubeList, GL_COMPILE);
  107. glBegin(GL_TRIANGLE_STRIP);
  108. glNormal3fv(scp[0]); glVertex3fv(scp[0]);
  109. glNormal3fv(scp[0]); glVertex3fv(scp[1]);
  110. glNormal3fv(scp[2]); glVertex3fv(scp[2]);
  111. glNormal3fv(scp[2]); glVertex3fv(scp[3]);
  112. glNormal3fv(scp[4]); glVertex3fv(scp[4]);
  113. glNormal3fv(scp[4]); glVertex3fv(scp[5]);
  114. glNormal3fv(scp[6]); glVertex3fv(scp[6]);
  115. glNormal3fv(scp[6]); glVertex3fv(scp[7]);
  116. glNormal3fv(scp[8]); glVertex3fv(scp[8]);
  117. glNormal3fv(scp[8]); glVertex3fv(scp[9]);
  118. glNormal3fv(scp[10]); glVertex3fv(scp[10]);
  119. glNormal3fv(scp[10]); glVertex3fv(scp[11]);
  120. glNormal3fv(scp[12]); glVertex3fv(scp[12]);
  121. glNormal3fv(scp[12]); glVertex3fv(scp[13]);
  122. glNormal3fv(scp[14]); glVertex3fv(scp[14]);
  123. glNormal3fv(scp[14]); glVertex3fv(scp[15]);
  124. glNormal3fv(scp[16]); glVertex3fv(scp[16]);
  125. glNormal3fv(scp[16]); glVertex3fv(scp[17]);
  126. glEnd();
  127. glEndList();
  128. }
  129. static void Init(void)
  130. {
  131. static float ambient[] = {0.1, 0.1, 0.1, 1.0};
  132. static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
  133. static float position[] = {90.0, 90.0, 0.0, 0.0};
  134. static float front_mat_shininess[] = {30.0};
  135. static float front_mat_specular[] = {0.0, 0.0, 0.0, 1.0};
  136. static float front_mat_diffuse[] = {0.0, 1.0, 0.0, 1.0};
  137. static float back_mat_shininess[] = {50.0};
  138. static float back_mat_specular[] = {0.0, 0.0, 1.0, 1.0};
  139. static float back_mat_diffuse[] = {1.0, 0.0, 0.0, 1.0};
  140. static float lmodel_ambient[] = {0.0, 0.0, 0.0, 1.0};
  141. static float fog_color[] = {0.8, 0.8, 0.8, 1.0};
  142. glFrontFace(GL_CW);
  143. glDepthFunc(GL_LEQUAL);
  144. glEnable(GL_DEPTH_TEST);
  145. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  146. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  147. glLightfv(GL_LIGHT0, GL_POSITION, position);
  148. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  149. glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
  150. glEnable(GL_LIGHTING);
  151. glEnable(GL_LIGHT0);
  152. glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
  153. glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
  154. glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
  155. glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
  156. glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
  157. glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
  158. glEnable(GL_FOG);
  159. glFogi(GL_FOG_MODE, GL_EXP);
  160. glFogf(GL_FOG_DENSITY, fogDensity);
  161. if (rgb) {
  162. glFogfv(GL_FOG_COLOR, fog_color);
  163. glClearColor(0.8, 0.8, 0.8, 1.0);
  164. } else {
  165. glFogi(GL_FOG_INDEX, 1<<5);
  166. tkSetFogRamp(5, 3);
  167. glClearIndex(128);
  168. }
  169. Build_lists();
  170. }
  171. static void Reshape(int width, int height)
  172. {
  173. glViewport(0, 0, (GLint)width, (GLint)height);
  174. glMatrixMode(GL_PROJECTION);
  175. glLoadIdentity();
  176. gluPerspective(45.0, 1.0, 1.0, 200.0);
  177. glMatrixMode(GL_MODELVIEW);
  178. }
  179. static GLenum Key(int key, GLenum mask)
  180. {
  181. switch (key) {
  182. case TK_ESCAPE:
  183. tkQuit();
  184. case TK_UP:
  185. rotX -= 5;
  186. break;
  187. case TK_DOWN:
  188. rotX += 5;
  189. break;
  190. case TK_LEFT:
  191. rotY -= 5;
  192. break;
  193. case TK_RIGHT:
  194. rotY += 5;
  195. break;
  196. case TK_D:
  197. if (rgb) {
  198. fogDensity *= 1.10;
  199. glFogf(GL_FOG_DENSITY, fogDensity);
  200. }
  201. break;
  202. case TK_d:
  203. if (rgb) {
  204. fogDensity /= 1.10;
  205. glFogf(GL_FOG_DENSITY, fogDensity);
  206. }
  207. break;
  208. default:
  209. return GL_FALSE;
  210. }
  211. return GL_TRUE;
  212. }
  213. static void Draw(void)
  214. {
  215. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  216. glPushMatrix();
  217. glTranslatef(0, 0, zTranslate);
  218. glRotatef(rotY, 0,1,0);
  219. glRotatef(rotX, 1,0,0);
  220. glScalef(1.0, 1.0, 10.0);
  221. glCallList(cubeList);
  222. glPopMatrix();
  223. glFlush();
  224. if (doubleBuffer) {
  225. tkSwapBuffers();
  226. }
  227. }
  228. static GLenum Args(int argc, char **argv)
  229. {
  230. GLint i;
  231. rgb = GL_TRUE;
  232. doubleBuffer = GL_FALSE;
  233. directRender = GL_FALSE;
  234. for (i = 1; i < argc; i++) {
  235. if (strcmp(argv[i], "-ci") == 0) {
  236. rgb = GL_FALSE;
  237. } else if (strcmp(argv[i], "-rgb") == 0) {
  238. rgb = GL_TRUE;
  239. } else if (strcmp(argv[i], "-sb") == 0) {
  240. doubleBuffer = GL_FALSE;
  241. } else if (strcmp(argv[i], "-db") == 0) {
  242. doubleBuffer = GL_TRUE;
  243. } else if (strcmp(argv[i], "-dr") == 0) {
  244. directRender = GL_TRUE;
  245. } else if (strcmp(argv[i], "-ir") == 0) {
  246. directRender = GL_FALSE;
  247. } else {
  248. printf("%s (Bad option).\n", argv[i]);
  249. return GL_FALSE;
  250. }
  251. }
  252. return GL_TRUE;
  253. }
  254. void main(int argc, char **argv)
  255. {
  256. GLenum type;
  257. if (Args(argc, argv) == GL_FALSE) {
  258. tkQuit();
  259. }
  260. tkInitPosition(0, 0, 300, 300);
  261. type = TK_DEPTH16;
  262. type |= (rgb) ? TK_RGB : TK_INDEX;
  263. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  264. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  265. tkInitDisplayMode(type);
  266. if (tkInitWindow("Fog Test") == GL_FALSE) {
  267. tkQuit();
  268. }
  269. Init();
  270. tkExposeFunc(Reshape);
  271. tkReshapeFunc(Reshape);
  272. tkKeyDownFunc(Key);
  273. tkDisplayFunc(Draw);
  274. tkExec();
  275. }