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.

159 lines
6.0 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 <windows.h>
  38. #include <GL/gl.h>
  39. #include <gl/glaux.h>
  40. #include "teapot.h"
  41. #define static
  42. long GRD;
  43. #define TEAPOTSOLID 0
  44. #define TEAPOTWIRE 1
  45. static GLuint teapots[2] = {0, 0};
  46. static float tex[2][2][2] = {{{0, 0},{1, 0}},{{0, 1},{1, 1}}};
  47. static void solidTeapot(long grid, GLdouble scale)
  48. {
  49. float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
  50. long i, j, k, l;
  51. if (grid < 2) grid = 7;
  52. GRD = grid;
  53. teapots[TEAPOTSOLID] = glGenLists (1);
  54. glNewList(teapots[TEAPOTSOLID], GL_COMPILE);
  55. glPushMatrix ();
  56. glRotatef ((GLfloat)270.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
  57. glScalef ((GLdouble)0.5*scale, (GLdouble)0.5*scale, (GLdouble)0.5*scale);
  58. glTranslatef ((GLfloat)0.0, (GLfloat)0.0, (GLfloat)-1.5);
  59. for (i = 0; i < 10; i++) {
  60. for (j = 0; j < 4; j++)
  61. for (k = 0; k < 4; k++)
  62. for (l = 0; l < 3; l++) {
  63. p[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  64. q[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  65. if (l == 1) q[j][k][l] *= (float)-1.0;
  66. if (i < 6) {
  67. r[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  68. if (l == 0) r[j][k][l] *= (float)-1.0;
  69. s[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  70. if (l == 0) s[j][k][l] *= (float)-1.0;
  71. if (l == 1) s[j][k][l] *= (float)-1.0;
  72. }
  73. }
  74. glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &tex[0][0][0]);
  75. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &p[0][0][0]);
  76. glEnable(GL_MAP2_VERTEX_3); glEnable(GL_MAP2_TEXTURE_COORD_2);
  77. glMapGrid2f(GRD, (GLfloat)0.0, (GLfloat)1.0, GRD, (GLfloat)0.0, (GLfloat)1.0);
  78. glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  79. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &q[0][0][0]);
  80. glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  81. if (i < 6) {
  82. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &r[0][0][0]);
  83. glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  84. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &s[0][0][0]);
  85. glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  86. }
  87. }
  88. glDisable(GL_MAP2_VERTEX_3); glDisable(GL_MAP2_TEXTURE_COORD_2);
  89. glPopMatrix ();
  90. glEndList();
  91. }
  92. static void wireTeapot(long grid, GLdouble scale)
  93. {
  94. float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
  95. long i, j, k, l;
  96. if (grid < 2) grid = 7;
  97. GRD = grid;
  98. teapots[TEAPOTWIRE] = glGenLists (1);
  99. glNewList(teapots[TEAPOTWIRE], GL_COMPILE);
  100. glPushMatrix ();
  101. glRotatef ((GLfloat)270.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
  102. glScalef ((GLdouble)0.5*scale, (GLdouble)0.5*scale, (GLdouble)0.5*scale);
  103. glTranslatef ((GLfloat)0.0, (GLfloat)0.0, (GLfloat)-1.5);
  104. for (i = 0; i < 10; i++) {
  105. for (j = 0; j < 4; j++)
  106. for (k = 0; k < 4; k++)
  107. for (l = 0; l < 3; l++) {
  108. p[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  109. q[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  110. if (l == 1) q[j][k][l] *= (float)-1.0;
  111. if (i < 6) {
  112. r[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  113. if (l == 0) r[j][k][l] *= (float)-1.0;
  114. s[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  115. if (l == 0) s[j][k][l] *= (float)-1.0;
  116. if (l == 1) s[j][k][l] *= (float)-1.0;
  117. }
  118. }
  119. glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &tex[0][0][0]);
  120. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &p[0][0][0]);
  121. glEnable(GL_MAP2_VERTEX_3); glEnable(GL_MAP2_TEXTURE_COORD_2);
  122. glMapGrid2f(GRD, (GLfloat)0.0, (GLfloat)1.0, GRD, (GLfloat)0.0, (GLfloat)1.0);
  123. glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  124. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &q[0][0][0]);
  125. glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  126. if (i < 6) {
  127. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &r[0][0][0]);
  128. glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  129. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &s[0][0][0]);
  130. glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  131. }
  132. }
  133. glDisable(GL_MAP2_VERTEX_3); glDisable(GL_MAP2_TEXTURE_COORD_2);
  134. glPopMatrix ();
  135. glEndList();
  136. }
  137. void auxSolidTeapot(GLdouble scale)
  138. {
  139. if (glIsList(teapots[TEAPOTSOLID]) == 0)
  140. solidTeapot (14, scale);
  141. glCallList(teapots[TEAPOTSOLID]);
  142. }
  143. void auxWireTeapot(GLdouble scale)
  144. {
  145. if (glIsList(teapots[TEAPOTWIRE]) == 0)
  146. wireTeapot (10, scale);
  147. glCallList(teapots[TEAPOTWIRE]);
  148. }