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.

176 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. /*
  38. * nurbs.c
  39. * This program shows a NURBS (Non-uniform rational B-splines)
  40. * surface, shaped like a heart.
  41. */
  42. #include <windows.h>
  43. #include <GL/gl.h>
  44. #include <GL/glu.h>
  45. #include "glaux.h"
  46. #define S_NUMPOINTS 13
  47. #define S_ORDER 3
  48. #define S_NUMKNOTS (S_NUMPOINTS + S_ORDER)
  49. #define T_NUMPOINTS 3
  50. #define T_ORDER 3
  51. #define T_NUMKNOTS (T_NUMPOINTS + T_ORDER)
  52. #define SQRT2 1.41421356237309504880
  53. /* initialized local data */
  54. GLfloat sknots[S_NUMKNOTS] =
  55. {-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0,
  56. 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 9.0, 9.0};
  57. GLfloat tknots[T_NUMKNOTS] = {1.0, 1.0, 1.0, 2.0, 2.0, 2.0};
  58. GLfloat ctlpoints[S_NUMPOINTS][T_NUMPOINTS][4] = {
  59. { {4.,2.,2.,1.},{4.,1.6,2.5,1.},{4.,2.,3.0,1.} },
  60. { {5.,4.,2.,1.},{5.,4.,2.5,1.},{5.,4.,3.0,1.} },
  61. { {6.,5.,2.,1.},{6.,5.,2.5,1.},{6.,5.,3.0,1.} },
  62. { {SQRT2*6.,SQRT2*6.,SQRT2*2.,SQRT2},
  63. {SQRT2*6.,SQRT2*6.,SQRT2*2.5,SQRT2},
  64. {SQRT2*6.,SQRT2*6.,SQRT2*3.0,SQRT2} },
  65. { {5.2,6.7,2.,1.},{5.2,6.7,2.5,1.},{5.2,6.7,3.0,1.} },
  66. { {SQRT2*4.,SQRT2*6.,SQRT2*2.,SQRT2},
  67. {SQRT2*4.,SQRT2*6.,SQRT2*2.5,SQRT2},
  68. {SQRT2*4.,SQRT2*6.,SQRT2*3.0,SQRT2} },
  69. { {4.,5.2,2.,1.},{4.,4.6,2.5,1.},{4.,5.2,3.0,1.} },
  70. { {SQRT2*4.,SQRT2*6.,SQRT2*2.,SQRT2},
  71. {SQRT2*4.,SQRT2*6.,SQRT2*2.5,SQRT2},
  72. {SQRT2*4.,SQRT2*6.,SQRT2*3.0,SQRT2} },
  73. { {2.8,6.7,2.,1.},{2.8,6.7,2.5,1.},{2.8,6.7,3.0,1.} },
  74. { {SQRT2*2.,SQRT2*6.,SQRT2*2.,SQRT2},
  75. {SQRT2*2.,SQRT2*6.,SQRT2*2.5,SQRT2},
  76. {SQRT2*2.,SQRT2*6.,SQRT2*3.0,SQRT2} },
  77. { {2.,5.,2.,1.},{2.,5.,2.5,1.},{2.,5.,3.0,1.} },
  78. { {3.,4.,2.,1.},{3.,4.,2.5,1.},{3.,4.,3.0,1.} },
  79. { {4.,2.,2.,1.},{4.,1.6,2.5,1.},{4.,2.,3.0,1.} }
  80. };
  81. GLUnurbsObj *theNurb;
  82. /* Initialize material property, light source, lighting model,
  83. * and depth buffer.
  84. */
  85. void myinit(void)
  86. {
  87. GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
  88. GLfloat mat_diffuse[] = { 1.0, 0.2, 1.0, 1.0 };
  89. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  90. GLfloat mat_shininess[] = { 50.0 };
  91. GLfloat light0_position[] = { 1.0, 0.1, 1.0, 0.0 };
  92. GLfloat light1_position[] = { -1.0, 0.1, 1.0, 0.0 };
  93. GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
  94. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  95. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  96. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  97. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  98. glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  99. glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  100. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  101. glEnable(GL_LIGHTING);
  102. glEnable(GL_LIGHT0);
  103. glEnable(GL_LIGHT1);
  104. glDepthFunc(GL_LESS);
  105. glEnable(GL_DEPTH_TEST);
  106. glEnable(GL_AUTO_NORMAL);
  107. theNurb = gluNewNurbsRenderer();
  108. glNewList (1, GL_COMPILE);
  109. gluBeginSurface(theNurb);
  110. /* gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 5.0); */
  111. gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
  112. gluNurbsSurface(theNurb,
  113. S_NUMKNOTS, sknots,
  114. T_NUMKNOTS, tknots,
  115. 4 * T_NUMPOINTS,
  116. 4,
  117. &ctlpoints[0][0][0],
  118. S_ORDER, T_ORDER,
  119. GL_MAP2_VERTEX_4);
  120. gluEndSurface(theNurb);
  121. glEndList ();
  122. }
  123. void display(void)
  124. {
  125. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  126. glColor3f(1.0, 1.0, 1.0);
  127. glPushMatrix();
  128. glTranslatef (4., 4.5, 2.5);
  129. glRotatef (220.0, 1., 0., 0.);
  130. glRotatef (115.0, 0., 1., 0.);
  131. glTranslatef (-4., -4.5, -2.5);
  132. glCallList (1);
  133. glPopMatrix();
  134. glFlush();
  135. }
  136. void myReshape(GLsizei w, GLsizei h)
  137. {
  138. glViewport(0, 0, w, h);
  139. glMatrixMode(GL_PROJECTION);
  140. glLoadIdentity();
  141. glFrustum(-2.0, 2.0, -2.0, 2.0, 0.8, 10.0);
  142. gluLookAt(7.0,4.5,4.0, 4.5,4.5,2.0, 6.0,-3.0,2.0);
  143. glMatrixMode(GL_MODELVIEW);
  144. glLoadIdentity();
  145. }
  146. /* Main Loop
  147. * Open window with initial window size, title bar,
  148. * RGBA display mode, and handle input events.
  149. */
  150. int main(int argc, char** argv)
  151. {
  152. auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH16);
  153. auxInitPosition (0, 0, 500, 500);
  154. auxInitWindow (argv[0]);
  155. myinit();
  156. auxReshapeFunc (myReshape);
  157. auxMainLoop(display);
  158. }