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.

212 lines
5.3 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. * light.c
  39. * This program demonstrates the use of the OpenGL lighting
  40. * model. A sphere is drawn using a grey material characteristic.
  41. * A single light source illuminates the object.
  42. */
  43. #include <windows.h>
  44. #include <GL/gl.h>
  45. #include <GL/glu.h>
  46. #include "glaux.h"
  47. GLboolean dbl_buf = GL_FALSE;
  48. GLboolean depth_buf = GL_TRUE;
  49. GLboolean dlist = GL_TRUE;
  50. double ang = 0.0;
  51. GLuint display_list;
  52. GLsizei win_w, win_h;
  53. void SolidSphere (GLdouble radius)
  54. {
  55. GLUquadricObj *quadObj;
  56. quadObj = gluNewQuadric ();
  57. gluQuadricDrawStyle (quadObj, GLU_FILL);
  58. gluQuadricNormals (quadObj, GLU_SMOOTH);
  59. gluSphere (quadObj, radius, 16, 16);
  60. }
  61. /* Initialize material property, light source, lighting model,
  62. * and depth buffer.
  63. */
  64. void myinit(void)
  65. {
  66. GLfloat mat_specular[] = { (GLfloat)1.0, (GLfloat)1.0, (GLfloat)1.0, (GLfloat)1.0 };
  67. GLfloat mat_shininess[] = { (GLfloat)50.0 };
  68. GLfloat light_position[] = { (GLfloat)0.0, (GLfloat)0.0, (GLfloat)1.0, (GLfloat)0.0 };
  69. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  70. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  71. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  72. glEnable(GL_LIGHTING);
  73. glEnable(GL_LIGHT0);
  74. if (depth_buf)
  75. {
  76. glDepthFunc(GL_LESS);
  77. glEnable(GL_DEPTH_TEST);
  78. }
  79. else
  80. {
  81. glEnable(GL_CULL_FACE);
  82. }
  83. if (dlist)
  84. {
  85. display_list = glGenLists(1);
  86. glNewList(display_list, GL_COMPILE);
  87. SolidSphere(1.0);
  88. glEndList();
  89. }
  90. }
  91. void display(void)
  92. {
  93. if (depth_buf)
  94. {
  95. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  96. }
  97. else
  98. {
  99. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  100. }
  101. if (dlist)
  102. {
  103. glCallList(display_list);
  104. }
  105. else
  106. {
  107. SolidSphere(1.0);
  108. }
  109. if (dbl_buf)
  110. {
  111. auxSwapBuffers();
  112. }
  113. else
  114. {
  115. glFlush();
  116. }
  117. }
  118. void SetProj(GLsizei w, GLsizei h)
  119. {
  120. double x, y, z;
  121. x = cos(ang)*2;
  122. y = 0;
  123. z = sin(ang)*2;
  124. glMatrixMode(GL_PROJECTION);
  125. glLoadIdentity();
  126. if (w <= h)
  127. {
  128. glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
  129. 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
  130. }
  131. else
  132. {
  133. glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
  134. 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
  135. }
  136. gluLookAt(x, y, z, 0, 0, 0, 0, 1, 0);
  137. glMatrixMode(GL_MODELVIEW);
  138. win_w = w;
  139. win_h = h;
  140. }
  141. #define PI 3.1415926535
  142. #define DTOR(deg) ((deg)*PI/180.0)
  143. void Idle(void)
  144. {
  145. ang += DTOR(3);
  146. SetProj(win_w, win_h);
  147. display();
  148. }
  149. void myReshape(GLsizei w, GLsizei h)
  150. {
  151. glViewport(0, 0, w, h);
  152. SetProj(w, h);
  153. glLoadIdentity();
  154. }
  155. /* Main Loop
  156. * Open window with initial window size, title bar,
  157. * RGBA display mode, and handle input events.
  158. */
  159. void __cdecl main(int argc, char** argv)
  160. {
  161. GLenum mode;
  162. int i;
  163. for (i = 1; i < argc; i++)
  164. {
  165. if (!strcmp(argv[i], "-db"))
  166. {
  167. dbl_buf = GL_TRUE;
  168. }
  169. else if (!strcmp(argv[i], "-cull"))
  170. {
  171. depth_buf = GL_FALSE;
  172. }
  173. else if (!strcmp(argv[i], "-nodlist"))
  174. {
  175. dlist = GL_FALSE;
  176. }
  177. }
  178. mode = AUX_RGB;
  179. mode |= dbl_buf ? AUX_DOUBLE : AUX_SINGLE;
  180. mode |= depth_buf ? AUX_DEPTH16 : 0;
  181. auxInitDisplayMode (mode);
  182. auxInitPosition (100, 50, 500, 500);
  183. auxInitWindow (argv[0]);
  184. myinit();
  185. auxReshapeFunc (myReshape);
  186. auxIdleFunc(Idle);
  187. auxMainLoop(display);
  188. }