Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

tesswind.c 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Copyright (c) 1993-1997, 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(R) is a registered trademark of Silicon Graphics, Inc.
  36. */
  37. /*
  38. * tesswind.c
  39. * This program demonstrates the winding rule polygon
  40. * tessellation property. Four tessellated objects are drawn,
  41. * each with very different contours. When the w key is pressed,
  42. * the objects are drawn with a different winding rule.
  43. */
  44. #include <GL/glut.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #ifdef GLU_VERSION_1_2
  48. /* Win32 calling conventions. */
  49. #ifndef CALLBACK
  50. #define CALLBACK
  51. #endif
  52. GLdouble currentWinding = GLU_TESS_WINDING_ODD;
  53. int currentShape = 0;
  54. GLUtesselator *tobj;
  55. GLuint list;
  56. /* Make four display lists,
  57. * each with a different tessellated object.
  58. */
  59. void makeNewLists (void) {
  60. int i;
  61. static GLdouble rects[12][3] =
  62. {{ 50.0, 50.0, 0.0}, {300.0, 50.0, 0.0},
  63. {300.0, 300.0, 0.0}, { 50.0, 300.0, 0.0},
  64. {100.0, 100.0, 0.0}, {250.0, 100.0, 0.0},
  65. {250.0, 250.0, 0.0}, {100.0, 250.0, 0.0},
  66. {150.0, 150.0, 0.0}, {200.0, 150.0, 0.0},
  67. {200.0, 200.0, 0.0}, {150.0, 200.0, 0.0}};
  68. static GLdouble spiral[16][3] =
  69. {{400.0, 250.0, 0.0}, {400.0, 50.0, 0.0},
  70. { 50.0, 50.0, 0.0}, { 50.0, 400.0, 0.0},
  71. {350.0, 400.0, 0.0}, {350.0, 100.0, 0.0},
  72. {100.0, 100.0, 0.0}, {100.0, 350.0, 0.0},
  73. {300.0, 350.0, 0.0}, {300.0, 150.0, 0.0},
  74. {150.0, 150.0, 0.0}, {150.0, 300.0, 0.0},
  75. {250.0, 300.0, 0.0}, {250.0, 200.0, 0.0},
  76. {200.0, 200.0, 0.0}, {200.0, 250.0, 0.0}};
  77. static GLdouble quad1[4][3] =
  78. {{ 50.0, 150.0, 0.0}, {350.0, 150.0, 0.0},
  79. {350.0, 200.0, 0.0}, { 50.0, 200.0, 0.0}};
  80. static GLdouble quad2[4][3] =
  81. {{100.0, 100.0, 0.0}, {300.0, 100.0, 0.0},
  82. {300.0, 350.0, 0.0}, {100.0, 350.0, 0.0}};
  83. static GLdouble tri[3][3] =
  84. {{200.0, 50.0, 0.0}, {250.0, 300.0, 0.0},
  85. {150.0, 300.0, 0.0}};
  86. gluTessProperty(tobj, GLU_TESS_WINDING_RULE,
  87. currentWinding);
  88. glNewList(list, GL_COMPILE);
  89. gluTessBeginPolygon(tobj, NULL);
  90. gluTessBeginContour(tobj);
  91. for (i = 0; i < 4; i++)
  92. gluTessVertex(tobj, rects[i], rects[i]);
  93. gluTessEndContour(tobj);
  94. gluTessBeginContour(tobj);
  95. for (i = 4; i < 8; i++)
  96. gluTessVertex(tobj, rects[i], rects[i]);
  97. gluTessEndContour(tobj);
  98. gluTessBeginContour(tobj);
  99. for (i = 8; i < 12; i++)
  100. gluTessVertex(tobj, rects[i], rects[i]);
  101. gluTessEndContour(tobj);
  102. gluTessEndPolygon(tobj);
  103. glEndList();
  104. glNewList(list+1, GL_COMPILE);
  105. gluTessBeginPolygon(tobj, NULL);
  106. gluTessBeginContour(tobj);
  107. for (i = 0; i < 4; i++)
  108. gluTessVertex(tobj, rects[i], rects[i]);
  109. gluTessEndContour(tobj);
  110. gluTessBeginContour(tobj);
  111. for (i = 7; i >= 4; i--)
  112. gluTessVertex(tobj, rects[i], rects[i]);
  113. gluTessEndContour(tobj);
  114. gluTessBeginContour(tobj);
  115. for (i = 11; i >= 8; i--)
  116. gluTessVertex(tobj, rects[i], rects[i]);
  117. gluTessEndContour(tobj);
  118. gluTessEndPolygon(tobj);
  119. glEndList();
  120. glNewList(list+2, GL_COMPILE);
  121. gluTessBeginPolygon(tobj, NULL);
  122. gluTessBeginContour(tobj);
  123. for (i = 0; i < 16; i++)
  124. gluTessVertex(tobj, spiral[i], spiral[i]);
  125. gluTessEndContour(tobj);
  126. gluTessEndPolygon(tobj);
  127. glEndList();
  128. glNewList(list+3, GL_COMPILE);
  129. gluTessBeginPolygon(tobj, NULL);
  130. gluTessBeginContour(tobj);
  131. for (i = 0; i < 4; i++)
  132. gluTessVertex(tobj, quad1[i], quad1[i]);
  133. gluTessEndContour(tobj);
  134. gluTessBeginContour(tobj);
  135. for (i = 0; i < 4; i++)
  136. gluTessVertex(tobj, quad2[i], quad2[i]);
  137. gluTessEndContour(tobj);
  138. gluTessBeginContour(tobj);
  139. for (i = 0; i < 3; i++)
  140. gluTessVertex(tobj, tri[i], tri[i]);
  141. gluTessEndContour(tobj);
  142. gluTessEndPolygon(tobj);
  143. glEndList();
  144. }
  145. void display (void) {
  146. glClear(GL_COLOR_BUFFER_BIT);
  147. glColor3f(1.0, 1.0, 1.0);
  148. glPushMatrix();
  149. glCallList(list);
  150. glTranslatef(0.0, 500.0, 0.0);
  151. glCallList(list+1);
  152. glTranslatef(500.0, -500.0, 0.0);
  153. glCallList(list+2);
  154. glTranslatef(0.0, 500.0, 0.0);
  155. glCallList(list+3);
  156. glPopMatrix();
  157. glFlush();
  158. }
  159. void CALLBACK beginCallback(GLenum which)
  160. {
  161. glBegin(which);
  162. }
  163. void CALLBACK errorCallback(GLenum errorCode)
  164. {
  165. const GLubyte *estring;
  166. estring = gluErrorString(errorCode);
  167. fprintf(stderr, "Tessellation Error: %s\n", estring);
  168. exit(0);
  169. }
  170. void CALLBACK endCallback(void)
  171. {
  172. glEnd();
  173. }
  174. /* combineCallback is used to create a new vertex when edges
  175. * intersect. coordinate location is trivial to calculate,
  176. * but weight[4] may be used to average color, normal, or texture
  177. * coordinate data.
  178. */
  179. /* ARGSUSED */
  180. void CALLBACK combineCallback(GLdouble coords[3], GLdouble *data[4],
  181. GLfloat weight[4], GLdouble **dataOut )
  182. {
  183. GLdouble *vertex;
  184. vertex = (GLdouble *) malloc(3 * sizeof(GLdouble));
  185. vertex[0] = coords[0];
  186. vertex[1] = coords[1];
  187. vertex[2] = coords[2];
  188. *dataOut = vertex;
  189. }
  190. void init(void)
  191. {
  192. glClearColor(0.0, 0.0, 0.0, 0.0);
  193. glShadeModel(GL_FLAT);
  194. tobj = gluNewTess();
  195. gluTessCallback(tobj, GLU_TESS_VERTEX,
  196. (GLvoid (CALLBACK*) ()) &glVertex3dv);
  197. gluTessCallback(tobj, GLU_TESS_BEGIN,
  198. (GLvoid (CALLBACK*) ()) &beginCallback);
  199. gluTessCallback(tobj, GLU_TESS_END,
  200. (GLvoid (CALLBACK*) ()) &endCallback);
  201. gluTessCallback(tobj, GLU_TESS_ERROR,
  202. (GLvoid (CALLBACK*) ()) &errorCallback);
  203. gluTessCallback(tobj, GLU_TESS_COMBINE,
  204. (GLvoid (CALLBACK*) ()) &combineCallback);
  205. list = glGenLists(4);
  206. makeNewLists();
  207. }
  208. void reshape(int w, int h)
  209. {
  210. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  211. glMatrixMode(GL_PROJECTION);
  212. glLoadIdentity();
  213. if (w <= h)
  214. gluOrtho2D(0.0, 1000.0, 0.0, 1000.0 * (GLdouble)h/(GLdouble)w);
  215. else
  216. gluOrtho2D(0.0, 1000.0 * (GLdouble)w/(GLdouble)h, 0.0, 1000.0);
  217. glMatrixMode(GL_MODELVIEW);
  218. glLoadIdentity();
  219. }
  220. /* ARGSUSED1 */
  221. void keyboard(unsigned char key, int x, int y)
  222. {
  223. switch (key) {
  224. case 'w':
  225. case 'W':
  226. if (currentWinding == GLU_TESS_WINDING_ODD)
  227. currentWinding = GLU_TESS_WINDING_NONZERO;
  228. else if (currentWinding == GLU_TESS_WINDING_NONZERO)
  229. currentWinding = GLU_TESS_WINDING_POSITIVE;
  230. else if (currentWinding == GLU_TESS_WINDING_POSITIVE)
  231. currentWinding = GLU_TESS_WINDING_NEGATIVE;
  232. else if (currentWinding == GLU_TESS_WINDING_NEGATIVE)
  233. currentWinding = GLU_TESS_WINDING_ABS_GEQ_TWO;
  234. else if (currentWinding == GLU_TESS_WINDING_ABS_GEQ_TWO)
  235. currentWinding = GLU_TESS_WINDING_ODD;
  236. makeNewLists();
  237. glutPostRedisplay();
  238. break;
  239. case 27:
  240. exit(0);
  241. break;
  242. default:
  243. break;
  244. }
  245. }
  246. int main(int argc, char** argv)
  247. {
  248. glutInit(&argc, argv);
  249. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  250. glutInitWindowSize(500, 500);
  251. glutCreateWindow(argv[0]);
  252. init();
  253. glutDisplayFunc(display);
  254. glutReshapeFunc(reshape);
  255. glutKeyboardFunc(keyboard);
  256. glutMainLoop();
  257. return 0;
  258. }
  259. #else
  260. int main(int argc, char** argv)
  261. {
  262. fprintf (stderr, "This program demonstrates the new tesselator API in GLU 1.2.\n");
  263. fprintf (stderr, "Your GLU library does not support this new interface, sorry.\n");
  264. return 0;
  265. }
  266. #endif