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.

166 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. * fog.c
  39. * This program draws 5 red teapots, each at a different
  40. * z distance from the eye, in different types of fog.
  41. * Pressing the left mouse button chooses between 3 types of
  42. * fog: exponential, exponential squared, and linear.
  43. * In this program, there is a fixed density value, as well
  44. * as fixed start and end values for the linear fog.
  45. */
  46. #include <windows.h>
  47. #include <stdio.h>
  48. #include <GL/gl.h>
  49. #include <GL/glu.h>
  50. #include <math.h>
  51. #include "glaux.h"
  52. GLint fogMode;
  53. void cycleFog (AUX_EVENTREC *event)
  54. {
  55. if (fogMode == GL_EXP) {
  56. fogMode = GL_EXP2;
  57. printf ("Fog mode is GL_EXP2\n");
  58. }
  59. else if (fogMode == GL_EXP2) {
  60. fogMode = GL_LINEAR;
  61. printf ("Fog mode is GL_LINEAR\n");
  62. glFogf (GL_FOG_START, 1.0);
  63. glFogf (GL_FOG_END, 5.0);
  64. }
  65. else if (fogMode == GL_LINEAR) {
  66. fogMode = GL_EXP;
  67. printf ("Fog mode is GL_EXP\n");
  68. }
  69. glFogi (GL_FOG_MODE, fogMode);
  70. }
  71. /* Initialize z-buffer, projection matrix, light source,
  72. * and lighting model. Do not specify a material property here.
  73. */
  74. void myinit(void)
  75. {
  76. GLfloat position[] = { 0.0, 3.0, 3.0, 0.0 };
  77. GLfloat local_view[] = { 0.0 };
  78. glEnable(GL_DEPTH_TEST);
  79. glDepthFunc(GL_LESS);
  80. glLightfv(GL_LIGHT0, GL_POSITION, position);
  81. glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
  82. glFrontFace (GL_CW);
  83. glEnable(GL_LIGHTING);
  84. glEnable(GL_LIGHT0);
  85. glEnable(GL_AUTO_NORMAL);
  86. glEnable(GL_NORMALIZE);
  87. glEnable(GL_FOG);
  88. {
  89. GLfloat density;
  90. GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0};
  91. fogMode = GL_EXP;
  92. glFogi (GL_FOG_MODE, fogMode);
  93. glFogfv (GL_FOG_COLOR, fogColor);
  94. glFogf (GL_FOG_DENSITY, 0.35);
  95. glHint (GL_FOG_HINT, GL_DONT_CARE);
  96. glClearColor(0.5, 0.5, 0.5, 1.0);
  97. }
  98. }
  99. void renderRedTeapot (GLfloat x, GLfloat y, GLfloat z)
  100. {
  101. float mat[3];
  102. mat[3] = 1.0f;
  103. glPushMatrix();
  104. glTranslatef (x, y, z);
  105. mat[0] = 0.1745; mat[1] = 0.01175; mat[2] = 0.01175;
  106. glMaterialfv (GL_FRONT, GL_AMBIENT, mat);
  107. mat[0] = 0.61424; mat[1] = 0.04136; mat[2] = 0.04136;
  108. glMaterialfv (GL_FRONT, GL_DIFFUSE, mat);
  109. mat[0] = 0.727811; mat[1] = 0.626959; mat[2] = 0.626959;
  110. glMaterialfv (GL_FRONT, GL_SPECULAR, mat);
  111. glMaterialf (GL_FRONT, GL_SHININESS, 0.6*128.0);
  112. auxSolidTeapot(1.0);
  113. glPopMatrix();
  114. }
  115. /* display() draws 5 teapots at different z positions.
  116. */
  117. void display(void)
  118. {
  119. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  120. renderRedTeapot (-4.0, -0.5, -1.0);
  121. renderRedTeapot (-2.0, -0.5, -2.0);
  122. renderRedTeapot (0.0, -0.5, -3.0);
  123. renderRedTeapot (2.0, -0.5, -4.0);
  124. renderRedTeapot (4.0, -0.5, -5.0);
  125. glFlush();
  126. }
  127. void myReshape(GLsizei w, GLsizei h)
  128. {
  129. glViewport(0, 0, w, h);
  130. glMatrixMode(GL_PROJECTION);
  131. glLoadIdentity();
  132. if (w <= (h*3))
  133. glOrtho (-6.0, 6.0, -2.0*((GLfloat) h*3)/(GLfloat) w,
  134. 2.0*((GLfloat) h*3)/(GLfloat) w, 0.0, 10.0);
  135. else
  136. glOrtho (-6.0*(GLfloat) w/((GLfloat) h*3),
  137. 6.0*(GLfloat) w/((GLfloat) h*3), -2.0, 2.0, 0.0, 10.0);
  138. glMatrixMode(GL_MODELVIEW);
  139. glLoadIdentity ();
  140. }
  141. /* Main Loop
  142. * Open window with initial window size, title bar,
  143. * RGBA display mode, depth buffer, and handle input events.
  144. */
  145. int main(int argc, char** argv)
  146. {
  147. auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH16);
  148. auxInitPosition (0, 0, 450, 150);
  149. auxInitWindow (argv[0]);
  150. auxMouseFunc (AUX_LEFTBUTTON, AUX_MOUSEDOWN, cycleFog);
  151. myinit();
  152. auxReshapeFunc (myReshape);
  153. auxMainLoop(display);
  154. }