2 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
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.
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.
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.
35 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
40 * This program demonstrates the winding rule polygon
41 * tessellation property. Four tessellated objects are drawn,
42 * each with very different contours. When the w key is pressed,
43 * the objects are drawn with a different winding rule.
49 #ifdef GLU_VERSION_1_2
51 /* Win32 calling conventions. */
56 GLdouble currentWinding
= GLU_TESS_WINDING_ODD
;
61 /* Make four display lists,
62 * each with a different tessellated object.
64 static void makeNewLists (void) {
66 static GLdouble rects
[12][3] =
67 {{ 50.0, 50.0, 0.0}, {300.0, 50.0, 0.0},
68 {300.0, 300.0, 0.0}, { 50.0, 300.0, 0.0},
69 {100.0, 100.0, 0.0}, {250.0, 100.0, 0.0},
70 {250.0, 250.0, 0.0}, {100.0, 250.0, 0.0},
71 {150.0, 150.0, 0.0}, {200.0, 150.0, 0.0},
72 {200.0, 200.0, 0.0}, {150.0, 200.0, 0.0}};
73 static GLdouble spiral
[16][3] =
74 {{400.0, 250.0, 0.0}, {400.0, 50.0, 0.0},
75 { 50.0, 50.0, 0.0}, { 50.0, 400.0, 0.0},
76 {350.0, 400.0, 0.0}, {350.0, 100.0, 0.0},
77 {100.0, 100.0, 0.0}, {100.0, 350.0, 0.0},
78 {300.0, 350.0, 0.0}, {300.0, 150.0, 0.0},
79 {150.0, 150.0, 0.0}, {150.0, 300.0, 0.0},
80 {250.0, 300.0, 0.0}, {250.0, 200.0, 0.0},
81 {200.0, 200.0, 0.0}, {200.0, 250.0, 0.0}};
82 static GLdouble quad1
[4][3] =
83 {{ 50.0, 150.0, 0.0}, {350.0, 150.0, 0.0},
84 {350.0, 200.0, 0.0}, { 50.0, 200.0, 0.0}};
85 static GLdouble quad2
[4][3] =
86 {{100.0, 100.0, 0.0}, {300.0, 100.0, 0.0},
87 {300.0, 350.0, 0.0}, {100.0, 350.0, 0.0}};
88 static GLdouble tri
[3][3] =
89 {{200.0, 50.0, 0.0}, {250.0, 300.0, 0.0},
92 gluTessProperty(tobj
, GLU_TESS_WINDING_RULE
,
95 glNewList(list
, GL_COMPILE
);
96 gluTessBeginPolygon(tobj
, NULL
);
97 gluTessBeginContour(tobj
);
98 for (i
= 0; i
< 4; i
++)
99 gluTessVertex(tobj
, rects
[i
], rects
[i
]);
100 gluTessEndContour(tobj
);
101 gluTessBeginContour(tobj
);
102 for (i
= 4; i
< 8; i
++)
103 gluTessVertex(tobj
, rects
[i
], rects
[i
]);
104 gluTessEndContour(tobj
);
105 gluTessBeginContour(tobj
);
106 for (i
= 8; i
< 12; i
++)
107 gluTessVertex(tobj
, rects
[i
], rects
[i
]);
108 gluTessEndContour(tobj
);
109 gluTessEndPolygon(tobj
);
112 glNewList(list
+1, GL_COMPILE
);
113 gluTessBeginPolygon(tobj
, NULL
);
114 gluTessBeginContour(tobj
);
115 for (i
= 0; i
< 4; i
++)
116 gluTessVertex(tobj
, rects
[i
], rects
[i
]);
117 gluTessEndContour(tobj
);
118 gluTessBeginContour(tobj
);
119 for (i
= 7; i
>= 4; i
--)
120 gluTessVertex(tobj
, rects
[i
], rects
[i
]);
121 gluTessEndContour(tobj
);
122 gluTessBeginContour(tobj
);
123 for (i
= 11; i
>= 8; i
--)
124 gluTessVertex(tobj
, rects
[i
], rects
[i
]);
125 gluTessEndContour(tobj
);
126 gluTessEndPolygon(tobj
);
129 glNewList(list
+2, GL_COMPILE
);
130 gluTessBeginPolygon(tobj
, NULL
);
131 gluTessBeginContour(tobj
);
132 for (i
= 0; i
< 16; i
++)
133 gluTessVertex(tobj
, spiral
[i
], spiral
[i
]);
134 gluTessEndContour(tobj
);
135 gluTessEndPolygon(tobj
);
138 glNewList(list
+3, GL_COMPILE
);
139 gluTessBeginPolygon(tobj
, NULL
);
140 gluTessBeginContour(tobj
);
141 for (i
= 0; i
< 4; i
++)
142 gluTessVertex(tobj
, quad1
[i
], quad1
[i
]);
143 gluTessEndContour(tobj
);
144 gluTessBeginContour(tobj
);
145 for (i
= 0; i
< 4; i
++)
146 gluTessVertex(tobj
, quad2
[i
], quad2
[i
]);
147 gluTessEndContour(tobj
);
148 gluTessBeginContour(tobj
);
149 for (i
= 0; i
< 3; i
++)
150 gluTessVertex(tobj
, tri
[i
], tri
[i
]);
151 gluTessEndContour(tobj
);
152 gluTessEndPolygon(tobj
);
156 static void display (void) {
157 glClear(GL_COLOR_BUFFER_BIT
);
158 glColor3f(1.0, 1.0, 1.0);
161 glTranslatef(0.0, 500.0, 0.0);
163 glTranslatef(500.0, -500.0, 0.0);
165 glTranslatef(0.0, 500.0, 0.0);
171 static void CALLBACK
beginCallback(GLenum which
)
176 static void CALLBACK
errorCallback(GLenum errorCode
)
178 const GLubyte
*estring
;
180 estring
= gluErrorString(errorCode
);
181 fprintf(stderr
, "Tessellation Error: %s\n", (char *) estring
);
185 static void CALLBACK
endCallback(void)
190 /* combineCallback is used to create a new vertex when edges
191 * intersect. coordinate location is trivial to calculate,
192 * but weight[4] may be used to average color, normal, or texture
196 static void CALLBACK
combineCallback(GLdouble coords
[3], GLdouble
*data
[4],
197 GLfloat weight
[4], GLdouble
**dataOut
)
200 vertex
= (GLdouble
*) malloc(3 * sizeof(GLdouble
));
202 vertex
[0] = coords
[0];
203 vertex
[1] = coords
[1];
204 vertex
[2] = coords
[2];
208 static void init(void)
210 glClearColor(0.0, 0.0, 0.0, 0.0);
211 glShadeModel(GL_FLAT
);
214 gluTessCallback(tobj
, GLU_TESS_VERTEX
,
215 (GLvoid (CALLBACK
*) ()) &glVertex3dv
);
216 gluTessCallback(tobj
, GLU_TESS_BEGIN
,
217 (GLvoid (CALLBACK
*) ()) &beginCallback
);
218 gluTessCallback(tobj
, GLU_TESS_END
,
219 (GLvoid (CALLBACK
*) ()) &endCallback
);
220 gluTessCallback(tobj
, GLU_TESS_ERROR
,
221 (GLvoid (CALLBACK
*) ()) &errorCallback
);
222 gluTessCallback(tobj
, GLU_TESS_COMBINE
,
223 (GLvoid (CALLBACK
*) ()) &combineCallback
);
225 list
= glGenLists(4);
229 static void reshape(int w
, int h
)
231 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
232 glMatrixMode(GL_PROJECTION
);
235 gluOrtho2D(0.0, 1000.0, 0.0, 1000.0 * (GLdouble
)h
/(GLdouble
)w
);
237 gluOrtho2D(0.0, 1000.0 * (GLdouble
)w
/(GLdouble
)h
, 0.0, 1000.0);
238 glMatrixMode(GL_MODELVIEW
);
243 static void keyboard(unsigned char key
, int x
, int y
)
248 if (currentWinding
== GLU_TESS_WINDING_ODD
)
249 currentWinding
= GLU_TESS_WINDING_NONZERO
;
250 else if (currentWinding
== GLU_TESS_WINDING_NONZERO
)
251 currentWinding
= GLU_TESS_WINDING_POSITIVE
;
252 else if (currentWinding
== GLU_TESS_WINDING_POSITIVE
)
253 currentWinding
= GLU_TESS_WINDING_NEGATIVE
;
254 else if (currentWinding
== GLU_TESS_WINDING_NEGATIVE
)
255 currentWinding
= GLU_TESS_WINDING_ABS_GEQ_TWO
;
256 else if (currentWinding
== GLU_TESS_WINDING_ABS_GEQ_TWO
)
257 currentWinding
= GLU_TESS_WINDING_ODD
;
269 int main(int argc
, char** argv
)
271 glutInit(&argc
, argv
);
272 glutInitDisplayMode(GLUT_SINGLE
| GLUT_RGB
);
273 glutInitWindowSize(500, 500);
274 glutCreateWindow(argv
[0]);
276 glutDisplayFunc(display
);
277 glutReshapeFunc(reshape
);
278 glutKeyboardFunc(keyboard
);
284 int main(int argc
, char** argv
)
286 fprintf (stderr
, "This program demonstrates the new tesselator API in GLU 1.2.\n");
287 fprintf (stderr
, "Your GLU library does not support this new interface, sorry.\n");