blob: 8b988e36c136202b3fe15806f0f5e2de25d0e68e [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001
2/*
3 * A demo of the GLU polygon tesselation functions written by Bogdan Sikorski.
Gareth Hughes16cdc6a2001-03-21 02:43:14 +00004 * Updated for GLU 1.3 tessellation by Gareth Hughes <gareth@valinux.com>
Gareth Hugheseb459c61999-11-04 04:00:42 +00005 */
jtgafb833d1999-08-19 00:55:39 +00006
jtgafb833d1999-08-19 00:55:39 +00007#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
Brianf42d4ab2007-04-26 07:46:59 -060010#include <GL/glut.h>
jtgafb833d1999-08-19 00:55:39 +000011
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000012#define MAX_POINTS 256
13#define MAX_CONTOURS 32
14#define MAX_TRIANGLES 256
jtgafb833d1999-08-19 00:55:39 +000015
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000016#ifndef GLCALLBACK
17#ifdef CALLBACK
18#define GLCALLBACK CALLBACK
19#else
20#define GLCALLBACK
21#endif
22#endif
jtgafb833d1999-08-19 00:55:39 +000023
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000024#ifdef GLU_VERSION_1_2
jtgafb833d1999-08-19 00:55:39 +000025
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000026typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries;
27typedef enum{ DEFINE, TESSELATED } mode_type;
28
29static GLsizei width, height;
30static GLuint contour_cnt;
31static GLuint triangle_cnt;
32
33static mode_type mode;
34static int menu;
35
36static GLuint list_start;
37
38static GLfloat edge_color[3];
39
40static struct {
41 GLfloat p[MAX_POINTS][2];
42 GLuint point_cnt;
43} contours[MAX_CONTOURS];
44
45static struct {
46 GLsizei no;
47 GLfloat p[3][2];
48 GLclampf color[3][3];
49} triangles[MAX_TRIANGLES];
50
51
52
53static void GLCALLBACK error_callback( GLenum err )
jtgafb833d1999-08-19 00:55:39 +000054{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000055 int len, i;
56 char const *str;
jtgafb833d1999-08-19 00:55:39 +000057
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000058 glColor3f( 0.9, 0.9, 0.9 );
59 glRasterPos2i( 5, 5 );
Brian Paulc4266ac2000-07-11 14:11:58 +000060
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000061 str = (const char *) gluErrorString( err );
62 len = strlen( str );
Gareth Hugheseb459c61999-11-04 04:00:42 +000063
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000064 for ( i = 0 ; i < len ; i++ ) {
65 glutBitmapCharacter( GLUT_BITMAP_9_BY_15, str[i] );
Gareth Hugheseb459c61999-11-04 04:00:42 +000066 }
jtgafb833d1999-08-19 00:55:39 +000067}
68
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000069static void GLCALLBACK begin_callback( GLenum mode )
jtgafb833d1999-08-19 00:55:39 +000070{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000071 /* Allow multiple triangles to be output inside the begin/end pair. */
72 triangle_cnt = 0;
73 triangles[triangle_cnt].no = 0;
74}
75
76static void GLCALLBACK edge_callback( GLenum flag )
77{
78 /* Persist the edge flag across triangles. */
79 if ( flag == GL_TRUE ) {
80 edge_color[0] = 1.0;
81 edge_color[1] = 1.0;
82 edge_color[2] = 0.5;
83 } else {
84 edge_color[0] = 1.0;
85 edge_color[1] = 0.0;
86 edge_color[2] = 0.0;
87 }
88}
89
90static void GLCALLBACK end_callback()
91{
Karl Schultz53d30c52002-10-18 17:47:35 +000092 GLuint i;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000093
94 glBegin( GL_LINES );
95
96 /* Output the three edges of each triangle as lines colored
97 according to their edge flag. */
98 for ( i = 0 ; i < triangle_cnt ; i++ ) {
99 glColor3f( triangles[i].color[0][0],
100 triangles[i].color[0][1],
101 triangles[i].color[0][2] );
102
103 glVertex2f( triangles[i].p[0][0], triangles[i].p[0][1] );
104 glVertex2f( triangles[i].p[1][0], triangles[i].p[1][1] );
105
106 glColor3f( triangles[i].color[1][0],
107 triangles[i].color[1][1],
108 triangles[i].color[1][2] );
109
110 glVertex2f( triangles[i].p[1][0], triangles[i].p[1][1] );
111 glVertex2f( triangles[i].p[2][0], triangles[i].p[2][1] );
112
113 glColor3f( triangles[i].color[2][0],
114 triangles[i].color[2][1],
115 triangles[i].color[2][2] );
116
117 glVertex2f( triangles[i].p[2][0], triangles[i].p[2][1] );
118 glVertex2f( triangles[i].p[0][0], triangles[i].p[0][1] );
119 }
120
Gareth Hugheseb459c61999-11-04 04:00:42 +0000121 glEnd();
jtgafb833d1999-08-19 00:55:39 +0000122}
123
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000124static void GLCALLBACK vertex_callback( void *data )
jtgafb833d1999-08-19 00:55:39 +0000125{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000126 GLsizei no;
127 GLfloat *p;
jtgafb833d1999-08-19 00:55:39 +0000128
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000129 p = (GLfloat *) data;
130 no = triangles[triangle_cnt].no;
131
132 triangles[triangle_cnt].p[no][0] = p[0];
133 triangles[triangle_cnt].p[no][1] = p[1];
134
135 triangles[triangle_cnt].color[no][0] = edge_color[0];
136 triangles[triangle_cnt].color[no][1] = edge_color[1];
137 triangles[triangle_cnt].color[no][2] = edge_color[2];
138
139 /* After every three vertices, initialize the next triangle. */
140 if ( ++(triangles[triangle_cnt].no) == 3 ) {
141 triangle_cnt++;
142 triangles[triangle_cnt].no = 0;
143 }
144}
145
146static void GLCALLBACK combine_callback( GLdouble coords[3],
147 GLdouble *vertex_data[4],
148 GLfloat weight[4], void **data )
149{
150 GLfloat *vertex;
151
152 vertex = (GLfloat *) malloc( 2 * sizeof(GLfloat) );
153
154 vertex[0] = (GLfloat) coords[0];
155 vertex[1] = (GLfloat) coords[1];
156
157 *data = vertex;
Gareth Hughes3b7a75a2000-01-23 21:25:39 +0000158}
159
160
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000161static void set_screen_wh( GLsizei w, GLsizei h )
jtgafb833d1999-08-19 00:55:39 +0000162{
Gareth Hugheseb459c61999-11-04 04:00:42 +0000163 width = w;
164 height = h;
jtgafb833d1999-08-19 00:55:39 +0000165}
166
Brian Paulf02a5f62002-07-12 15:54:01 +0000167typedef void (GLAPIENTRY *callback_t)();
168
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000169static void tesse( void )
Brian Paulc4266ac2000-07-11 14:11:58 +0000170{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000171 GLUtesselator *tobj;
172 GLdouble data[3];
173 GLuint i, j, point_cnt;
174
175 list_start = glGenLists( 2 );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000176
177 tobj = gluNewTess();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000178
179 if ( tobj != NULL ) {
180 gluTessNormal( tobj, 0.0, 0.0, 1.0 );
Brian Paulf02a5f62002-07-12 15:54:01 +0000181 gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) glBegin );
182 gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) glVertex2fv );
183 gluTessCallback( tobj, GLU_TESS_END, (callback_t) glEnd );
184 gluTessCallback( tobj, GLU_TESS_ERROR, (callback_t) error_callback );
185 gluTessCallback( tobj, GLU_TESS_COMBINE, (callback_t) combine_callback );
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000186
187 glNewList( list_start, GL_COMPILE );
188 gluBeginPolygon( tobj );
189
190 for ( j = 0 ; j <= contour_cnt ; j++ ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000191 point_cnt = contours[j].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000192 gluNextContour( tobj, GLU_UNKNOWN );
193
194 for ( i = 0 ; i < point_cnt ; i++ ) {
195 data[0] = (GLdouble)( contours[j].p[i][0] );
196 data[1] = (GLdouble)( contours[j].p[i][1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000197 data[2] = 0.0;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000198 gluTessVertex( tobj, data, contours[j].p[i] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000199 }
200 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000201
202 gluEndPolygon( tobj );
203 glEndList();
204
Brian Paulf02a5f62002-07-12 15:54:01 +0000205 gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) begin_callback );
206 gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) vertex_callback );
207 gluTessCallback( tobj, GLU_TESS_END, (callback_t) end_callback );
208 gluTessCallback( tobj, GLU_TESS_EDGE_FLAG, (callback_t) edge_callback );
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000209
210 glNewList( list_start + 1, GL_COMPILE );
211 gluBeginPolygon( tobj );
212
213 for ( j = 0 ; j <= contour_cnt ; j++ ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000214 point_cnt = contours[j].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000215 gluNextContour( tobj, GLU_UNKNOWN );
216
217 for ( i = 0 ; i < point_cnt ; i++ ) {
218 data[0] = (GLdouble)( contours[j].p[i][0] );
219 data[1] = (GLdouble)( contours[j].p[i][1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000220 data[2] = 0.0;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000221 gluTessVertex( tobj, data, contours[j].p[i] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000222 }
223 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000224
225 gluEndPolygon( tobj );
226 glEndList();
227
228 gluDeleteTess( tobj );
229
230 glutMouseFunc( NULL );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000231 mode = TESSELATED;
232 }
jtgafb833d1999-08-19 00:55:39 +0000233}
234
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000235static void left_down( int x1, int y1 )
jtgafb833d1999-08-19 00:55:39 +0000236{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000237 GLfloat P[2];
238 GLuint point_cnt;
jtgafb833d1999-08-19 00:55:39 +0000239
Gareth Hugheseb459c61999-11-04 04:00:42 +0000240 /* translate GLUT into GL coordinates */
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000241
Gareth Hugheseb459c61999-11-04 04:00:42 +0000242 P[0] = x1;
243 P[1] = height - y1;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000244
Gareth Hugheseb459c61999-11-04 04:00:42 +0000245 point_cnt = contours[contour_cnt].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000246
Gareth Hugheseb459c61999-11-04 04:00:42 +0000247 contours[contour_cnt].p[point_cnt][0] = P[0];
248 contours[contour_cnt].p[point_cnt][1] = P[1];
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000249
250 glBegin( GL_LINES );
251
252 if ( point_cnt ) {
253 glVertex2fv( contours[contour_cnt].p[point_cnt-1] );
254 glVertex2fv( P );
255 } else {
256 glVertex2fv( P );
257 glVertex2fv( P );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000258 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000259
Gareth Hugheseb459c61999-11-04 04:00:42 +0000260 glEnd();
261 glFinish();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000262
263 contours[contour_cnt].point_cnt++;
jtgafb833d1999-08-19 00:55:39 +0000264}
265
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000266static void middle_down( int x1, int y1 )
jtgafb833d1999-08-19 00:55:39 +0000267{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000268 GLuint point_cnt;
269 (void) x1;
270 (void) y1;
jtgafb833d1999-08-19 00:55:39 +0000271
Gareth Hugheseb459c61999-11-04 04:00:42 +0000272 point_cnt = contours[contour_cnt].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000273
274 if ( point_cnt > 2 ) {
275 glBegin( GL_LINES );
276
277 glVertex2fv( contours[contour_cnt].p[0] );
278 glVertex2fv( contours[contour_cnt].p[point_cnt-1] );
279
Gareth Hugheseb459c61999-11-04 04:00:42 +0000280 contours[contour_cnt].p[point_cnt][0] = -1;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000281
Gareth Hugheseb459c61999-11-04 04:00:42 +0000282 glEnd();
283 glFinish();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000284
Gareth Hugheseb459c61999-11-04 04:00:42 +0000285 contour_cnt++;
286 contours[contour_cnt].point_cnt = 0;
287 }
jtgafb833d1999-08-19 00:55:39 +0000288}
289
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000290static void mouse_clicked( int button, int state, int x, int y )
Brian Paulc4266ac2000-07-11 14:11:58 +0000291{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000292 x -= x%10;
293 y -= y%10;
294
295 switch ( button ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000296 case GLUT_LEFT_BUTTON:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000297 if ( state == GLUT_DOWN ) {
298 left_down( x, y );
299 }
Gareth Hugheseb459c61999-11-04 04:00:42 +0000300 break;
301 case GLUT_MIDDLE_BUTTON:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000302 if ( state == GLUT_DOWN ) {
303 middle_down( x, y );
304 }
Gareth Hugheseb459c61999-11-04 04:00:42 +0000305 break;
306 }
jtgafb833d1999-08-19 00:55:39 +0000307}
308
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000309static void display( void )
jtgafb833d1999-08-19 00:55:39 +0000310{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000311 GLuint i,j;
Karl Schultz53d30c52002-10-18 17:47:35 +0000312 GLsizei ii, jj;
Gareth Hugheseb459c61999-11-04 04:00:42 +0000313 GLuint point_cnt;
jtgafb833d1999-08-19 00:55:39 +0000314
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000315 glClear( GL_COLOR_BUFFER_BIT );
316
317 switch ( mode ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000318 case DEFINE:
319 /* draw grid */
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000320 glColor3f( 0.6, 0.5, 0.5 );
321
322 glBegin( GL_LINES );
323
Karl Schultz53d30c52002-10-18 17:47:35 +0000324 for ( ii = 0 ; ii < width ; ii += 10 ) {
325 for ( jj = 0 ; jj < height ; jj += 10 ) {
326 glVertex2i( 0, jj );
327 glVertex2i( width, jj );
328 glVertex2i( ii, height );
329 glVertex2i( ii, 0 );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000330 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000331 }
332
Brian Pauld25df352000-03-27 15:46:12 +0000333 glEnd();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000334
335 glColor3f( 1.0, 1.0, 0.0 );
336
337 for ( i = 0 ; i <= contour_cnt ; i++ ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000338 point_cnt = contours[i].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000339
340 glBegin( GL_LINES );
341
342 switch ( point_cnt ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000343 case 0:
344 break;
345 case 1:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000346 glVertex2fv( contours[i].p[0] );
347 glVertex2fv( contours[i].p[0] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000348 break;
349 case 2:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000350 glVertex2fv( contours[i].p[0] );
351 glVertex2fv( contours[i].p[1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000352 break;
353 default:
354 --point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000355 for ( j = 0 ; j < point_cnt ; j++ ) {
356 glVertex2fv( contours[i].p[j] );
357 glVertex2fv( contours[i].p[j+1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000358 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000359 if ( contours[i].p[j+1][0] == -1 ) {
360 glVertex2fv( contours[i].p[0] );
361 glVertex2fv( contours[i].p[j] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000362 }
363 break;
364 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000365
Gareth Hugheseb459c61999-11-04 04:00:42 +0000366 glEnd();
367 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000368
Gareth Hugheseb459c61999-11-04 04:00:42 +0000369 glFinish();
370 break;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000371
Gareth Hugheseb459c61999-11-04 04:00:42 +0000372 case TESSELATED:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000373 /* draw triangles */
374 glColor3f( 0.7, 0.7, 0.0 );
375 glCallList( list_start );
376
377 glLineWidth( 2.0 );
378 glCallList( list_start + 1 );
379 glLineWidth( 1.0 );
380
381 glFlush();
Gareth Hugheseb459c61999-11-04 04:00:42 +0000382 break;
383 }
384
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000385 glColor3f( 1.0, 1.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000386}
387
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000388static void clear( void )
jtgafb833d1999-08-19 00:55:39 +0000389{
Gareth Hugheseb459c61999-11-04 04:00:42 +0000390 contour_cnt = 0;
391 contours[0].point_cnt = 0;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000392 triangle_cnt = 0;
393
394 glutMouseFunc( mouse_clicked );
395
Gareth Hugheseb459c61999-11-04 04:00:42 +0000396 mode = DEFINE;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000397
398 glDeleteLists( list_start, 2 );
399 list_start = 0;
jtgafb833d1999-08-19 00:55:39 +0000400}
401
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000402static void quit( void )
jtgafb833d1999-08-19 00:55:39 +0000403{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000404 exit( 0 );
jtgafb833d1999-08-19 00:55:39 +0000405}
406
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000407static void menu_selected( int entry )
jtgafb833d1999-08-19 00:55:39 +0000408{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000409 switch ( entry ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000410 case CLEAR:
411 clear();
412 break;
413 case TESSELATE:
414 tesse();
415 break;
416 case QUIT:
417 quit();
418 break;
419 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000420
421 glutPostRedisplay();
jtgafb833d1999-08-19 00:55:39 +0000422}
423
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000424static void key_pressed( unsigned char key, int x, int y )
Brian Paulc4266ac2000-07-11 14:11:58 +0000425{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000426 (void) x;
427 (void) y;
428
429 switch ( key ) {
430 case 'c':
431 case 'C':
432 clear();
433 break;
Gareth Hugheseb459c61999-11-04 04:00:42 +0000434 case 't':
435 case 'T':
436 tesse();
437 break;
Gareth Hughesf5328c52001-03-21 02:44:36 +0000438 case 27:
Gareth Hugheseb459c61999-11-04 04:00:42 +0000439 case 'q':
440 case 'Q':
441 quit();
442 break;
443 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000444
445 glutPostRedisplay();
jtgafb833d1999-08-19 00:55:39 +0000446}
447
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000448static void myinit( void )
jtgafb833d1999-08-19 00:55:39 +0000449{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000450 /* clear background to gray */
451 glClearColor( 0.4, 0.4, 0.4, 0.0 );
452 glShadeModel( GL_FLAT );
453 glPolygonMode( GL_FRONT, GL_FILL );
jtgafb833d1999-08-19 00:55:39 +0000454
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000455 menu = glutCreateMenu( menu_selected );
456
457 glutAddMenuEntry( "clear", CLEAR );
458 glutAddMenuEntry( "tesselate", TESSELATE );
459 glutAddMenuEntry( "quit", QUIT );
460
461 glutAttachMenu( GLUT_RIGHT_BUTTON );
462
463 glutMouseFunc( mouse_clicked );
464 glutKeyboardFunc( key_pressed );
465
Gareth Hugheseb459c61999-11-04 04:00:42 +0000466 contour_cnt = 0;
467 mode = DEFINE;
jtgafb833d1999-08-19 00:55:39 +0000468}
469
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000470static void reshape( GLsizei w, GLsizei h )
jtgafb833d1999-08-19 00:55:39 +0000471{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000472 glViewport( 0, 0, w, h );
473
474 glMatrixMode( GL_PROJECTION );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000475 glLoadIdentity();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000476 glOrtho( 0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0 );
477
478 glMatrixMode( GL_MODELVIEW );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000479 glLoadIdentity();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000480
481 set_screen_wh( w, h );
jtgafb833d1999-08-19 00:55:39 +0000482}
483
Gareth Hughesfa6be6e2001-03-21 02:47:32 +0000484#endif
485
jtgafb833d1999-08-19 00:55:39 +0000486
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000487static void usage( void )
jtgafb833d1999-08-19 00:55:39 +0000488{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000489 printf( "Use left mouse button to place vertices.\n" );
490 printf( "Press middle mouse button when done.\n" );
491 printf( "Select tesselate from the pop-up menu.\n" );
jtgafb833d1999-08-19 00:55:39 +0000492}
493
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000494
495int main( int argc, char **argv )
jtgafb833d1999-08-19 00:55:39 +0000496{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000497 const char *version = (const char *) gluGetString( GLU_VERSION );
498 printf( "GLU version string: %s\n", version );
499 if ( strstr( version, "1.0" ) || strstr( version, "1.1" ) ) {
500 fprintf( stderr, "Sorry, this demo reqiures GLU 1.2 or later.\n" );
501 exit( 1 );
502 }
503
Brian Paulc4266ac2000-07-11 14:11:58 +0000504 usage();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000505
Brian Paul263f4322009-12-18 08:12:55 -0700506 glutInitWindowSize( 400, 400 );
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000507 glutInit( &argc, argv );
508 glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000509 glutCreateWindow( argv[0] );
510
Gareth Hughesfa6be6e2001-03-21 02:47:32 +0000511 /* GH: Bit of a hack...
512 */
513#ifdef GLU_VERSION_1_2
Brian Paulc4266ac2000-07-11 14:11:58 +0000514 myinit();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000515
516 glutDisplayFunc( display );
517 glutReshapeFunc( reshape );
518
Brian Paulc4266ac2000-07-11 14:11:58 +0000519 glutMainLoop();
Gareth Hughesfa6be6e2001-03-21 02:47:32 +0000520#endif
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000521
Brian Paulc4266ac2000-07-11 14:11:58 +0000522 return 0;
jtgafb833d1999-08-19 00:55:39 +0000523}