From eb459c60708cc3fd5d71567d4ddf2db91aa25d78 Mon Sep 17 00:00:00 2001 From: Gareth Hughes Date: Thu, 4 Nov 1999 04:00:42 +0000 Subject: [PATCH] Updated demo for new GLU 1.3 tessellation. Added optimized rendering by saving the output of the tessellation into display lists. --- progs/demos/tessdemo.c | 765 ++++++++++++++++++++++++++++--------------------- 1 file changed, 440 insertions(+), 325 deletions(-) diff --git a/progs/demos/tessdemo.c b/progs/demos/tessdemo.c index c0d0242..7b3cf9e 100644 --- a/progs/demos/tessdemo.c +++ b/progs/demos/tessdemo.c @@ -1,4 +1,4 @@ -/* $Id: tessdemo.c,v 1.2 1999/09/19 20:09:00 tanner Exp $ */ +/* $Id: tessdemo.c,v 1.3 1999/11/04 04:00:42 gareth Exp $ */ /* * A demo of the GLU polygon tesselation functions written by Bogdan Sikorski. @@ -8,9 +8,16 @@ cc -g -ansi -prototypes -fullwarn -float -I../include -DSHM tess_demo.c -L../lib -lglut -lMesaGLU -lMesaGL -lm -lX11 -lXext -lXmu -lfpe -lXext -o tess_demo */ +/* + * Updated for GLU 1.3 tessellation by Gareth Hughes + */ /* * $Log: tessdemo.c,v $ + * Revision 1.3 1999/11/04 04:00:42 gareth + * Updated demo for new GLU 1.3 tessellation. Added optimized rendering + * by saving the output of the tessellation into display lists. + * * Revision 1.2 1999/09/19 20:09:00 tanner * * lots of autoconf updates @@ -44,29 +51,9 @@ #include #include -#define MAX_POINTS 200 -#define MAX_CONTOURS 50 - -int menu; -typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries; -typedef enum{ DEFINE, TESSELATED } mode_type; -struct -{ - GLint p[MAX_POINTS][2]; - GLuint point_cnt; -} contours[MAX_CONTOURS]; -GLuint contour_cnt; -GLsizei width,height; -mode_type mode; - -struct -{ - GLsizei no; - GLfloat color[3]; - GLint p[3][2]; - GLclampf p_color[3][3]; -} triangle; - +#define MAX_POINTS 256 +#define MAX_CONTOURS 32 +#define MAX_TRIANGLES 256 #ifndef GLCALLBACK #ifdef CALLBACK @@ -76,368 +63,496 @@ struct #endif #endif +typedef enum{ QUIT, TESSELATE, CLEAR } menu_entries; +typedef enum{ DEFINE, TESSELATED } mode_type; + +static GLsizei width, height; +static GLuint contour_cnt; +static GLuint triangle_cnt; -void GLCALLBACK my_error(GLenum err) +static mode_type mode; +static int menu; + +static GLuint list_start; + +static GLfloat edge_color[3]; + +static struct { - int len,i; - char const *str; - - glColor3f(0.9,0.9,0.9); - glRasterPos2i(5,5); - str=(const char *)gluErrorString(err); - len=strlen(str); - for(i=0;i2) - { - glBegin(GL_LINES); - glVertex2iv(contours[contour_cnt].p[0]); - glVertex2iv(contours[contour_cnt].p[point_cnt-1]); - contours[contour_cnt].p[point_cnt][0]= -1; - glEnd(); - glFinish(); - contour_cnt++; - contours[contour_cnt].point_cnt=0; - } + GLuint point_cnt; + (void) x1; + (void) y1; + + point_cnt = contours[contour_cnt].point_cnt; + + if ( point_cnt > 2 ) + { + glBegin( GL_LINES ); + + glVertex2iv( contours[contour_cnt].p[0] ); + glVertex2iv( contours[contour_cnt].p[point_cnt-1] ); + + contours[contour_cnt].p[point_cnt][0] = -1; + + glEnd(); + glFinish(); + + contour_cnt++; + contours[contour_cnt].point_cnt = 0; + } } -void mouse_clicked(int button,int state,int x,int y) +void mouse_clicked( int button, int state, int x, int y ) { - x-= x%10; - y-= y%10; - switch(button) - { - case GLUT_LEFT_BUTTON: - if(state==GLUT_DOWN) - left_down(x,y); - break; - case GLUT_MIDDLE_BUTTON: - if(state==GLUT_DOWN) - middle_down(x,y); - break; - } + x -= x%10; + y -= y%10; + + switch ( button ) + { + case GLUT_LEFT_BUTTON: + if ( state == GLUT_DOWN ) { + left_down( x, y ); + } + break; + case GLUT_MIDDLE_BUTTON: + if ( state == GLUT_DOWN ) { + middle_down( x, y ); + } + break; + } } -void display(void) +void display( void ) { - GLuint i,j; - GLuint point_cnt; - - glClear(GL_COLOR_BUFFER_BIT); - switch(mode) - { - case DEFINE: - /* draw grid */ - glColor3f (0.6,0.5,0.5); - glBegin(GL_LINES); - for(i=0;i