blob: 581dec90d5a9f27106b10023eb1e8899558bcf19 [file] [log] [blame]
Karl Schultz53d30c52002-10-18 17:47:35 +00001/* $Id: tessdemo.c,v 1.13 2002/10/18 17:47:36 kschultz Exp $ */
jtgafb833d1999-08-19 00:55:39 +00002
3/*
4 * A demo of the GLU polygon tesselation functions written by Bogdan Sikorski.
Gareth Hughes16cdc6a2001-03-21 02:43:14 +00005 * Updated for GLU 1.3 tessellation by Gareth Hughes <gareth@valinux.com>
Gareth Hugheseb459c61999-11-04 04:00:42 +00006 */
jtgafb833d1999-08-19 00:55:39 +00007
jtgafb833d1999-08-19 00:55:39 +00008#include <GL/glut.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000013#define MAX_POINTS 256
14#define MAX_CONTOURS 32
15#define MAX_TRIANGLES 256
jtgafb833d1999-08-19 00:55:39 +000016
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000017#ifndef GLCALLBACK
18#ifdef CALLBACK
19#define GLCALLBACK CALLBACK
20#else
21#define GLCALLBACK
22#endif
23#endif
jtgafb833d1999-08-19 00:55:39 +000024
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000025#ifdef GLU_VERSION_1_2
jtgafb833d1999-08-19 00:55:39 +000026
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000027typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries;
28typedef enum{ DEFINE, TESSELATED } mode_type;
29
30static GLsizei width, height;
31static GLuint contour_cnt;
32static GLuint triangle_cnt;
33
34static mode_type mode;
35static int menu;
36
37static GLuint list_start;
38
39static GLfloat edge_color[3];
40
41static struct {
42 GLfloat p[MAX_POINTS][2];
43 GLuint point_cnt;
44} contours[MAX_CONTOURS];
45
46static struct {
47 GLsizei no;
48 GLfloat p[3][2];
49 GLclampf color[3][3];
50} triangles[MAX_TRIANGLES];
51
52
53
54static void GLCALLBACK error_callback( GLenum err )
jtgafb833d1999-08-19 00:55:39 +000055{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000056 int len, i;
57 char const *str;
jtgafb833d1999-08-19 00:55:39 +000058
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000059 glColor3f( 0.9, 0.9, 0.9 );
60 glRasterPos2i( 5, 5 );
Brian Paulc4266ac2000-07-11 14:11:58 +000061
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000062 str = (const char *) gluErrorString( err );
63 len = strlen( str );
Gareth Hugheseb459c61999-11-04 04:00:42 +000064
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000065 for ( i = 0 ; i < len ; i++ ) {
66 glutBitmapCharacter( GLUT_BITMAP_9_BY_15, str[i] );
Gareth Hugheseb459c61999-11-04 04:00:42 +000067 }
jtgafb833d1999-08-19 00:55:39 +000068}
69
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000070static void GLCALLBACK begin_callback( GLenum mode )
jtgafb833d1999-08-19 00:55:39 +000071{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000072 /* Allow multiple triangles to be output inside the begin/end pair. */
73 triangle_cnt = 0;
74 triangles[triangle_cnt].no = 0;
75}
76
77static void GLCALLBACK edge_callback( GLenum flag )
78{
79 /* Persist the edge flag across triangles. */
80 if ( flag == GL_TRUE ) {
81 edge_color[0] = 1.0;
82 edge_color[1] = 1.0;
83 edge_color[2] = 0.5;
84 } else {
85 edge_color[0] = 1.0;
86 edge_color[1] = 0.0;
87 edge_color[2] = 0.0;
88 }
89}
90
91static void GLCALLBACK end_callback()
92{
Karl Schultz53d30c52002-10-18 17:47:35 +000093 GLuint i;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +000094
95 glBegin( GL_LINES );
96
97 /* Output the three edges of each triangle as lines colored
98 according to their edge flag. */
99 for ( i = 0 ; i < triangle_cnt ; i++ ) {
100 glColor3f( triangles[i].color[0][0],
101 triangles[i].color[0][1],
102 triangles[i].color[0][2] );
103
104 glVertex2f( triangles[i].p[0][0], triangles[i].p[0][1] );
105 glVertex2f( triangles[i].p[1][0], triangles[i].p[1][1] );
106
107 glColor3f( triangles[i].color[1][0],
108 triangles[i].color[1][1],
109 triangles[i].color[1][2] );
110
111 glVertex2f( triangles[i].p[1][0], triangles[i].p[1][1] );
112 glVertex2f( triangles[i].p[2][0], triangles[i].p[2][1] );
113
114 glColor3f( triangles[i].color[2][0],
115 triangles[i].color[2][1],
116 triangles[i].color[2][2] );
117
118 glVertex2f( triangles[i].p[2][0], triangles[i].p[2][1] );
119 glVertex2f( triangles[i].p[0][0], triangles[i].p[0][1] );
120 }
121
Gareth Hugheseb459c61999-11-04 04:00:42 +0000122 glEnd();
jtgafb833d1999-08-19 00:55:39 +0000123}
124
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000125static void GLCALLBACK vertex_callback( void *data )
jtgafb833d1999-08-19 00:55:39 +0000126{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000127 GLsizei no;
128 GLfloat *p;
jtgafb833d1999-08-19 00:55:39 +0000129
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000130 p = (GLfloat *) data;
131 no = triangles[triangle_cnt].no;
132
133 triangles[triangle_cnt].p[no][0] = p[0];
134 triangles[triangle_cnt].p[no][1] = p[1];
135
136 triangles[triangle_cnt].color[no][0] = edge_color[0];
137 triangles[triangle_cnt].color[no][1] = edge_color[1];
138 triangles[triangle_cnt].color[no][2] = edge_color[2];
139
140 /* After every three vertices, initialize the next triangle. */
141 if ( ++(triangles[triangle_cnt].no) == 3 ) {
142 triangle_cnt++;
143 triangles[triangle_cnt].no = 0;
144 }
145}
146
147static void GLCALLBACK combine_callback( GLdouble coords[3],
148 GLdouble *vertex_data[4],
149 GLfloat weight[4], void **data )
150{
151 GLfloat *vertex;
152
153 vertex = (GLfloat *) malloc( 2 * sizeof(GLfloat) );
154
155 vertex[0] = (GLfloat) coords[0];
156 vertex[1] = (GLfloat) coords[1];
157
158 *data = vertex;
Gareth Hughes3b7a75a2000-01-23 21:25:39 +0000159}
160
161
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000162static void set_screen_wh( GLsizei w, GLsizei h )
jtgafb833d1999-08-19 00:55:39 +0000163{
Gareth Hugheseb459c61999-11-04 04:00:42 +0000164 width = w;
165 height = h;
jtgafb833d1999-08-19 00:55:39 +0000166}
167
Brian Paulf02a5f62002-07-12 15:54:01 +0000168typedef void (GLAPIENTRY *callback_t)();
169
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000170static void tesse( void )
Brian Paulc4266ac2000-07-11 14:11:58 +0000171{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000172 GLUtesselator *tobj;
173 GLdouble data[3];
174 GLuint i, j, point_cnt;
175
176 list_start = glGenLists( 2 );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000177
178 tobj = gluNewTess();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000179
180 if ( tobj != NULL ) {
181 gluTessNormal( tobj, 0.0, 0.0, 1.0 );
Brian Paulf02a5f62002-07-12 15:54:01 +0000182 gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) glBegin );
183 gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) glVertex2fv );
184 gluTessCallback( tobj, GLU_TESS_END, (callback_t) glEnd );
185 gluTessCallback( tobj, GLU_TESS_ERROR, (callback_t) error_callback );
186 gluTessCallback( tobj, GLU_TESS_COMBINE, (callback_t) combine_callback );
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000187
188 glNewList( list_start, GL_COMPILE );
189 gluBeginPolygon( tobj );
190
191 for ( j = 0 ; j <= contour_cnt ; j++ ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000192 point_cnt = contours[j].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000193 gluNextContour( tobj, GLU_UNKNOWN );
194
195 for ( i = 0 ; i < point_cnt ; i++ ) {
196 data[0] = (GLdouble)( contours[j].p[i][0] );
197 data[1] = (GLdouble)( contours[j].p[i][1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000198 data[2] = 0.0;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000199 gluTessVertex( tobj, data, contours[j].p[i] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000200 }
201 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000202
203 gluEndPolygon( tobj );
204 glEndList();
205
Brian Paulf02a5f62002-07-12 15:54:01 +0000206 gluTessCallback( tobj, GLU_TESS_BEGIN, (callback_t) begin_callback );
207 gluTessCallback( tobj, GLU_TESS_VERTEX, (callback_t) vertex_callback );
208 gluTessCallback( tobj, GLU_TESS_END, (callback_t) end_callback );
209 gluTessCallback( tobj, GLU_TESS_EDGE_FLAG, (callback_t) edge_callback );
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000210
211 glNewList( list_start + 1, GL_COMPILE );
212 gluBeginPolygon( tobj );
213
214 for ( j = 0 ; j <= contour_cnt ; j++ ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000215 point_cnt = contours[j].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000216 gluNextContour( tobj, GLU_UNKNOWN );
217
218 for ( i = 0 ; i < point_cnt ; i++ ) {
219 data[0] = (GLdouble)( contours[j].p[i][0] );
220 data[1] = (GLdouble)( contours[j].p[i][1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000221 data[2] = 0.0;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000222 gluTessVertex( tobj, data, contours[j].p[i] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000223 }
224 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000225
226 gluEndPolygon( tobj );
227 glEndList();
228
229 gluDeleteTess( tobj );
230
231 glutMouseFunc( NULL );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000232 mode = TESSELATED;
233 }
jtgafb833d1999-08-19 00:55:39 +0000234}
235
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000236static void left_down( int x1, int y1 )
jtgafb833d1999-08-19 00:55:39 +0000237{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000238 GLfloat P[2];
239 GLuint point_cnt;
jtgafb833d1999-08-19 00:55:39 +0000240
Gareth Hugheseb459c61999-11-04 04:00:42 +0000241 /* translate GLUT into GL coordinates */
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000242
Gareth Hugheseb459c61999-11-04 04:00:42 +0000243 P[0] = x1;
244 P[1] = height - y1;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000245
Gareth Hugheseb459c61999-11-04 04:00:42 +0000246 point_cnt = contours[contour_cnt].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000247
Gareth Hugheseb459c61999-11-04 04:00:42 +0000248 contours[contour_cnt].p[point_cnt][0] = P[0];
249 contours[contour_cnt].p[point_cnt][1] = P[1];
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000250
251 glBegin( GL_LINES );
252
253 if ( point_cnt ) {
254 glVertex2fv( contours[contour_cnt].p[point_cnt-1] );
255 glVertex2fv( P );
256 } else {
257 glVertex2fv( P );
258 glVertex2fv( P );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000259 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000260
Gareth Hugheseb459c61999-11-04 04:00:42 +0000261 glEnd();
262 glFinish();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000263
264 contours[contour_cnt].point_cnt++;
jtgafb833d1999-08-19 00:55:39 +0000265}
266
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000267static void middle_down( int x1, int y1 )
jtgafb833d1999-08-19 00:55:39 +0000268{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000269 GLuint point_cnt;
270 (void) x1;
271 (void) y1;
jtgafb833d1999-08-19 00:55:39 +0000272
Gareth Hugheseb459c61999-11-04 04:00:42 +0000273 point_cnt = contours[contour_cnt].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000274
275 if ( point_cnt > 2 ) {
276 glBegin( GL_LINES );
277
278 glVertex2fv( contours[contour_cnt].p[0] );
279 glVertex2fv( contours[contour_cnt].p[point_cnt-1] );
280
Gareth Hugheseb459c61999-11-04 04:00:42 +0000281 contours[contour_cnt].p[point_cnt][0] = -1;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000282
Gareth Hugheseb459c61999-11-04 04:00:42 +0000283 glEnd();
284 glFinish();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000285
Gareth Hugheseb459c61999-11-04 04:00:42 +0000286 contour_cnt++;
287 contours[contour_cnt].point_cnt = 0;
288 }
jtgafb833d1999-08-19 00:55:39 +0000289}
290
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000291static void mouse_clicked( int button, int state, int x, int y )
Brian Paulc4266ac2000-07-11 14:11:58 +0000292{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000293 x -= x%10;
294 y -= y%10;
295
296 switch ( button ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000297 case GLUT_LEFT_BUTTON:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000298 if ( state == GLUT_DOWN ) {
299 left_down( x, y );
300 }
Gareth Hugheseb459c61999-11-04 04:00:42 +0000301 break;
302 case GLUT_MIDDLE_BUTTON:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000303 if ( state == GLUT_DOWN ) {
304 middle_down( x, y );
305 }
Gareth Hugheseb459c61999-11-04 04:00:42 +0000306 break;
307 }
jtgafb833d1999-08-19 00:55:39 +0000308}
309
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000310static void display( void )
jtgafb833d1999-08-19 00:55:39 +0000311{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000312 GLuint i,j;
Karl Schultz53d30c52002-10-18 17:47:35 +0000313 GLsizei ii, jj;
Gareth Hugheseb459c61999-11-04 04:00:42 +0000314 GLuint point_cnt;
jtgafb833d1999-08-19 00:55:39 +0000315
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000316 glClear( GL_COLOR_BUFFER_BIT );
317
318 switch ( mode ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000319 case DEFINE:
320 /* draw grid */
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000321 glColor3f( 0.6, 0.5, 0.5 );
322
323 glBegin( GL_LINES );
324
Karl Schultz53d30c52002-10-18 17:47:35 +0000325 for ( ii = 0 ; ii < width ; ii += 10 ) {
326 for ( jj = 0 ; jj < height ; jj += 10 ) {
327 glVertex2i( 0, jj );
328 glVertex2i( width, jj );
329 glVertex2i( ii, height );
330 glVertex2i( ii, 0 );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000331 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000332 }
333
Brian Pauld25df352000-03-27 15:46:12 +0000334 glEnd();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000335
336 glColor3f( 1.0, 1.0, 0.0 );
337
338 for ( i = 0 ; i <= contour_cnt ; i++ ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000339 point_cnt = contours[i].point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000340
341 glBegin( GL_LINES );
342
343 switch ( point_cnt ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000344 case 0:
345 break;
346 case 1:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000347 glVertex2fv( contours[i].p[0] );
348 glVertex2fv( contours[i].p[0] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000349 break;
350 case 2:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000351 glVertex2fv( contours[i].p[0] );
352 glVertex2fv( contours[i].p[1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000353 break;
354 default:
355 --point_cnt;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000356 for ( j = 0 ; j < point_cnt ; j++ ) {
357 glVertex2fv( contours[i].p[j] );
358 glVertex2fv( contours[i].p[j+1] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000359 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000360 if ( contours[i].p[j+1][0] == -1 ) {
361 glVertex2fv( contours[i].p[0] );
362 glVertex2fv( contours[i].p[j] );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000363 }
364 break;
365 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000366
Gareth Hugheseb459c61999-11-04 04:00:42 +0000367 glEnd();
368 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000369
Gareth Hugheseb459c61999-11-04 04:00:42 +0000370 glFinish();
371 break;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000372
Gareth Hugheseb459c61999-11-04 04:00:42 +0000373 case TESSELATED:
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000374 /* draw triangles */
375 glColor3f( 0.7, 0.7, 0.0 );
376 glCallList( list_start );
377
378 glLineWidth( 2.0 );
379 glCallList( list_start + 1 );
380 glLineWidth( 1.0 );
381
382 glFlush();
Gareth Hugheseb459c61999-11-04 04:00:42 +0000383 break;
384 }
385
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000386 glColor3f( 1.0, 1.0, 0.0 );
jtgafb833d1999-08-19 00:55:39 +0000387}
388
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000389static void clear( void )
jtgafb833d1999-08-19 00:55:39 +0000390{
Gareth Hugheseb459c61999-11-04 04:00:42 +0000391 contour_cnt = 0;
392 contours[0].point_cnt = 0;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000393 triangle_cnt = 0;
394
395 glutMouseFunc( mouse_clicked );
396
Gareth Hugheseb459c61999-11-04 04:00:42 +0000397 mode = DEFINE;
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000398
399 glDeleteLists( list_start, 2 );
400 list_start = 0;
jtgafb833d1999-08-19 00:55:39 +0000401}
402
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000403static void quit( void )
jtgafb833d1999-08-19 00:55:39 +0000404{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000405 exit( 0 );
jtgafb833d1999-08-19 00:55:39 +0000406}
407
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000408static void menu_selected( int entry )
jtgafb833d1999-08-19 00:55:39 +0000409{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000410 switch ( entry ) {
Gareth Hugheseb459c61999-11-04 04:00:42 +0000411 case CLEAR:
412 clear();
413 break;
414 case TESSELATE:
415 tesse();
416 break;
417 case QUIT:
418 quit();
419 break;
420 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000421
422 glutPostRedisplay();
jtgafb833d1999-08-19 00:55:39 +0000423}
424
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000425static void key_pressed( unsigned char key, int x, int y )
Brian Paulc4266ac2000-07-11 14:11:58 +0000426{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000427 (void) x;
428 (void) y;
429
430 switch ( key ) {
431 case 'c':
432 case 'C':
433 clear();
434 break;
Gareth Hugheseb459c61999-11-04 04:00:42 +0000435 case 't':
436 case 'T':
437 tesse();
438 break;
Gareth Hughesf5328c52001-03-21 02:44:36 +0000439 case 27:
Gareth Hugheseb459c61999-11-04 04:00:42 +0000440 case 'q':
441 case 'Q':
442 quit();
443 break;
444 }
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000445
446 glutPostRedisplay();
jtgafb833d1999-08-19 00:55:39 +0000447}
448
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000449static void myinit( void )
jtgafb833d1999-08-19 00:55:39 +0000450{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000451 /* clear background to gray */
452 glClearColor( 0.4, 0.4, 0.4, 0.0 );
453 glShadeModel( GL_FLAT );
454 glPolygonMode( GL_FRONT, GL_FILL );
jtgafb833d1999-08-19 00:55:39 +0000455
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000456 menu = glutCreateMenu( menu_selected );
457
458 glutAddMenuEntry( "clear", CLEAR );
459 glutAddMenuEntry( "tesselate", TESSELATE );
460 glutAddMenuEntry( "quit", QUIT );
461
462 glutAttachMenu( GLUT_RIGHT_BUTTON );
463
464 glutMouseFunc( mouse_clicked );
465 glutKeyboardFunc( key_pressed );
466
Gareth Hugheseb459c61999-11-04 04:00:42 +0000467 contour_cnt = 0;
468 mode = DEFINE;
jtgafb833d1999-08-19 00:55:39 +0000469}
470
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000471static void reshape( GLsizei w, GLsizei h )
jtgafb833d1999-08-19 00:55:39 +0000472{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000473 glViewport( 0, 0, w, h );
474
475 glMatrixMode( GL_PROJECTION );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000476 glLoadIdentity();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000477 glOrtho( 0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0 );
478
479 glMatrixMode( GL_MODELVIEW );
Gareth Hugheseb459c61999-11-04 04:00:42 +0000480 glLoadIdentity();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000481
482 set_screen_wh( w, h );
jtgafb833d1999-08-19 00:55:39 +0000483}
484
Gareth Hughesfa6be6e2001-03-21 02:47:32 +0000485#endif
486
jtgafb833d1999-08-19 00:55:39 +0000487
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000488static void usage( void )
jtgafb833d1999-08-19 00:55:39 +0000489{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000490 printf( "Use left mouse button to place vertices.\n" );
491 printf( "Press middle mouse button when done.\n" );
492 printf( "Select tesselate from the pop-up menu.\n" );
jtgafb833d1999-08-19 00:55:39 +0000493}
494
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000495
496int main( int argc, char **argv )
jtgafb833d1999-08-19 00:55:39 +0000497{
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000498 const char *version = (const char *) gluGetString( GLU_VERSION );
499 printf( "GLU version string: %s\n", version );
500 if ( strstr( version, "1.0" ) || strstr( version, "1.1" ) ) {
501 fprintf( stderr, "Sorry, this demo reqiures GLU 1.2 or later.\n" );
502 exit( 1 );
503 }
504
Brian Paulc4266ac2000-07-11 14:11:58 +0000505 usage();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000506
507 glutInit( &argc, argv );
508 glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
509 glutInitWindowSize( 400, 400 );
510 glutCreateWindow( argv[0] );
511
Gareth Hughesfa6be6e2001-03-21 02:47:32 +0000512 /* GH: Bit of a hack...
513 */
514#ifdef GLU_VERSION_1_2
Brian Paulc4266ac2000-07-11 14:11:58 +0000515 myinit();
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000516
517 glutDisplayFunc( display );
518 glutReshapeFunc( reshape );
519
Brian Paulc4266ac2000-07-11 14:11:58 +0000520 glutMainLoop();
Gareth Hughesfa6be6e2001-03-21 02:47:32 +0000521#endif
Gareth Hughes16cdc6a2001-03-21 02:43:14 +0000522
Brian Paulc4266ac2000-07-11 14:11:58 +0000523 return 0;
jtgafb833d1999-08-19 00:55:39 +0000524}