Clone of mesa.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* Copyright (c) Mark J. Kilgard, 1994. */
  2. /**
  3. * (c) Copyright 1993, Silicon Graphics, Inc.
  4. * ALL RIGHTS RESERVED
  5. * Permission to use, copy, modify, and distribute this software for
  6. * any purpose and without fee is hereby granted, provided that the above
  7. * copyright notice appear in all copies and that both the copyright notice
  8. * and this permission notice appear in supporting documentation, and that
  9. * the name of Silicon Graphics, Inc. not be used in advertising
  10. * or publicity pertaining to distribution of the software without specific,
  11. * written prior permission.
  12. *
  13. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  22. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25. *
  26. * US Government Users Restricted Rights
  27. * Use, duplication, or disclosure by the Government is subject to
  28. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30. * clause at DFARS 252.227-7013 and/or in similar or successor
  31. * clauses in the FAR or the DOD or NASA FAR Supplement.
  32. * Unpublished-- rights reserved under the copyright laws of the
  33. * United States. Contractor/manufacturer is Silicon Graphics,
  34. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  35. *
  36. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37. */
  38. /* bezsurf.c
  39. * This program renders a lighted, filled Bezier surface,
  40. * using two-dimensional evaluators.
  41. */
  42. #include <stdlib.h>
  43. #include <GL/glut.h>
  44. GLfloat ctrlpoints[4][4][3] =
  45. {
  46. {
  47. {-1.5, -1.5, 4.0},
  48. {-0.5, -1.5, 2.0},
  49. {0.5, -1.5, -1.0},
  50. {1.5, -1.5, 2.0}},
  51. {
  52. {-1.5, -0.5, 1.0},
  53. {-0.5, -0.5, 3.0},
  54. {0.5, -0.5, 0.0},
  55. {1.5, -0.5, -1.0}},
  56. {
  57. {-1.5, 0.5, 4.0},
  58. {-0.5, 0.5, 0.0},
  59. {0.5, 0.5, 3.0},
  60. {1.5, 0.5, 4.0}},
  61. {
  62. {-1.5, 1.5, -2.0},
  63. {-0.5, 1.5, -2.0},
  64. {0.5, 1.5, 0.0},
  65. {1.5, 1.5, -1.0}}
  66. };
  67. void
  68. initlights(void)
  69. {
  70. GLfloat ambient[] =
  71. {0.2, 0.2, 0.2, 1.0};
  72. GLfloat position[] =
  73. {0.0, 0.0, 2.0, 1.0};
  74. GLfloat mat_diffuse[] =
  75. {0.6, 0.6, 0.6, 1.0};
  76. GLfloat mat_specular[] =
  77. {1.0, 1.0, 1.0, 1.0};
  78. GLfloat mat_shininess[] =
  79. {50.0};
  80. glEnable(GL_LIGHTING);
  81. glEnable(GL_LIGHT0);
  82. glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  83. glLightfv(GL_LIGHT0, GL_POSITION, position);
  84. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  85. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  86. glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  87. }
  88. void
  89. display(void)
  90. {
  91. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  92. glPushMatrix();
  93. glRotatef(85.0, 1.0, 1.0, 1.0);
  94. glEvalMesh2(GL_FILL, 0, 20, 0, 20);
  95. glPopMatrix();
  96. glFlush();
  97. }
  98. void
  99. myinit(void)
  100. {
  101. glClearColor(0.0, 0.0, 0.0, 1.0);
  102. glEnable(GL_DEPTH_TEST);
  103. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
  104. 0, 1, 12, 4, &ctrlpoints[0][0][0]);
  105. glEnable(GL_MAP2_VERTEX_3);
  106. glEnable(GL_AUTO_NORMAL);
  107. glEnable(GL_NORMALIZE);
  108. glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
  109. initlights(); /* for lighted version only */
  110. }
  111. void
  112. myReshape(int w, int h)
  113. {
  114. glViewport(0, 0, w, h);
  115. glMatrixMode(GL_PROJECTION);
  116. glLoadIdentity();
  117. if (w <= h)
  118. glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w,
  119. 4.0 * (GLfloat) h / (GLfloat) w, -4.0, 4.0);
  120. else
  121. glOrtho(-4.0 * (GLfloat) w / (GLfloat) h,
  122. 4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -4.0, 4.0);
  123. glMatrixMode(GL_MODELVIEW);
  124. glLoadIdentity();
  125. }
  126. static void
  127. key(unsigned char k, int x, int y)
  128. {
  129. switch (k) {
  130. case 27: /* Escape */
  131. exit(0);
  132. break;
  133. default:
  134. return;
  135. }
  136. glutPostRedisplay();
  137. }
  138. int
  139. main(int argc, char **argv)
  140. {
  141. glutInit(&argc, argv);
  142. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  143. glutCreateWindow(argv[0]);
  144. myinit();
  145. glutReshapeFunc(myReshape);
  146. glutDisplayFunc(display);
  147. glutKeyboardFunc(key);
  148. glutMainLoop();
  149. return 0; /* ANSI C requires main to return int. */
  150. }