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.

230 lines
7.2 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. /* accpersp.c
  38. */
  39. #include <windows.h>
  40. #include <GL/gl.h>
  41. #include <GL/glu.h>
  42. #include <math.h>
  43. #include "glaux.h"
  44. #include "jitter.h"
  45. #define PI_ 3.14159265358979323846
  46. /* accFrustum()
  47. * The first 6 arguments are identical to the glFrustum() call.
  48. *
  49. * pixdx and pixdy are anti-alias jitter in pixels.
  50. * Set both equal to 0.0 for no anti-alias jitter.
  51. * eyedx and eyedy are depth-of field jitter in pixels.
  52. * Set both equal to 0.0 for no depth of field effects.
  53. *
  54. * focus is distance from eye to plane in focus.
  55. * focus must be greater than, but not equal to 0.0.
  56. *
  57. * Note that accFrustum() calls glTranslatef(). You will
  58. * probably want to insure that your ModelView matrix has been
  59. * initialized to identity before calling accFrustum().
  60. */
  61. void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
  62. GLdouble znear, GLdouble zfar, GLdouble pixdx, GLdouble pixdy,
  63. GLdouble eyedx, GLdouble eyedy, GLdouble focus)
  64. {
  65. GLdouble xwsize, ywsize;
  66. GLdouble dx, dy;
  67. GLint viewport[4];
  68. glGetIntegerv (GL_VIEWPORT, viewport);
  69. xwsize = right - left;
  70. ywsize = top - bottom;
  71. dx = -(pixdx*xwsize/(GLdouble) viewport[2] + eyedx*znear/focus);
  72. dy = -(pixdy*ywsize/(GLdouble) viewport[3] + eyedy*znear/focus);
  73. glMatrixMode(GL_PROJECTION);
  74. glLoadIdentity();
  75. glFrustum (left + dx, right + dx, bottom + dy, top + dy, znear, zfar);
  76. glMatrixMode(GL_MODELVIEW);
  77. glLoadIdentity();
  78. glTranslatef (-eyedx, -eyedy, 0.0);
  79. }
  80. /* accPerspective()
  81. *
  82. * The first 4 arguments are identical to the gluPerspective() call.
  83. * pixdx and pixdy are anti-alias jitter in pixels.
  84. * Set both equal to 0.0 for no anti-alias jitter.
  85. * eyedx and eyedy are depth-of field jitter in pixels.
  86. * Set both equal to 0.0 for no depth of field effects.
  87. *
  88. * focus is distance from eye to plane in focus.
  89. * focus must be greater than, but not equal to 0.0.
  90. *
  91. * Note that accPerspective() calls accFrustum().
  92. */
  93. void accPerspective(GLdouble fovy, GLdouble aspect,
  94. GLdouble znear, GLdouble zfar, GLdouble pixdx, GLdouble pixdy,
  95. GLdouble eyedx, GLdouble eyedy, GLdouble focus)
  96. {
  97. GLdouble fov2,left,right,bottom,top;
  98. fov2 = ((fovy*PI_) / 180.0) / 2.0;
  99. top = znear / (cos(fov2) / sin(fov2));
  100. bottom = -top;
  101. right = top * aspect;
  102. left = -right;
  103. accFrustum (left, right, bottom, top, znear, zfar,
  104. pixdx, pixdy, eyedx, eyedy, focus);
  105. }
  106. /* Initialize lighting and other values.
  107. */
  108. void myinit(void)
  109. {
  110. GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
  111. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  112. GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 };
  113. GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
  114. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  115. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  116. glMaterialf(GL_FRONT, GL_SHININESS, 50.0);
  117. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  118. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient);
  119. glEnable(GL_LIGHTING);
  120. glEnable(GL_LIGHT0);
  121. glDepthFunc(GL_LESS);
  122. glEnable(GL_DEPTH_TEST);
  123. glShadeModel (GL_FLAT);
  124. glClearColor(0.0, 0.0, 0.0, 0.0);
  125. glClearAccum(0.0, 0.0, 0.0, 0.0);
  126. }
  127. void displayObjects(void)
  128. {
  129. GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  130. GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  131. GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  132. GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };
  133. glPushMatrix ();
  134. glTranslatef (0.0, 0.0, -5.0);
  135. glRotatef (30.0, 1.0, 0.0, 0.0);
  136. glPushMatrix ();
  137. glTranslatef (-0.80, 0.35, 0.0);
  138. glRotatef (100.0, 1.0, 0.0, 0.0);
  139. glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse);
  140. auxSolidTorus (0.275, 0.85);
  141. glPopMatrix ();
  142. glPushMatrix ();
  143. glTranslatef (-0.75, -0.50, 0.0);
  144. glRotatef (45.0, 0.0, 0.0, 1.0);
  145. glRotatef (45.0, 1.0, 0.0, 0.0);
  146. glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse);
  147. auxSolidCube (1.5);
  148. glPopMatrix ();
  149. glPushMatrix ();
  150. glTranslatef (0.75, 0.60, 0.0);
  151. glRotatef (30.0, 1.0, 0.0, 0.0);
  152. glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse);
  153. auxSolidSphere (1.0);
  154. glPopMatrix ();
  155. glPushMatrix ();
  156. glTranslatef (0.70, -0.90, 0.25);
  157. glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse);
  158. auxSolidOctahedron (1.0);
  159. glPopMatrix ();
  160. glPopMatrix ();
  161. }
  162. #define ACSIZE 8
  163. void display(void)
  164. {
  165. GLint viewport[4];
  166. int jitter;
  167. glGetIntegerv (GL_VIEWPORT, viewport);
  168. glClear(GL_ACCUM_BUFFER_BIT);
  169. for (jitter = 0; jitter < ACSIZE; jitter++) {
  170. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  171. accPerspective (50.0,
  172. (GLdouble) viewport[2]/(GLdouble) viewport[3],
  173. 1.0, 15.0, j8[jitter].x, j8[jitter].y,
  174. 0.0, 0.0, 1.0);
  175. displayObjects ();
  176. glAccum(GL_ACCUM, 1.0/ACSIZE);
  177. glFlush();
  178. auxSwapBuffers();
  179. }
  180. glAccum (GL_RETURN, 1.0);
  181. glFlush();
  182. auxSwapBuffers();
  183. }
  184. void myReshape(GLsizei w, GLsizei h)
  185. {
  186. glViewport(0, 0, w, h);
  187. }
  188. /* Main Loop
  189. * Open window with initial window size, title bar,
  190. * RGBA display mode, and handle input events.
  191. */
  192. int main(int argc, char** argv)
  193. {
  194. auxInitDisplayMode (AUX_DOUBLE | AUX_RGB
  195. | AUX_ACCUM | AUX_DEPTH16);
  196. auxInitPosition (0, 0, 250, 250);
  197. auxInitWindow (argv[0]);
  198. myinit();
  199. auxReshapeFunc (myReshape);
  200. auxMainLoop(display);
  201. }