--- ray/src/common/rglsurf.c 1998/06/09 11:18:36 3.1 +++ ray/src/common/rglsurf.c 2003/02/25 02:47:22 3.5 @@ -1,13 +1,12 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rglsurf.c,v 3.5 2003/02/25 02:47:22 greg Exp $"; #endif - /* * Convert Radiance -> OpenGL surfaces. */ +#include "copyright.h" + #include "radogl.h" #ifndef NSLICES @@ -29,6 +28,7 @@ static char *glu_rout = "unk"; /* active GLU routine * #define NOPOLY() if (curpolysize) {glEnd(); curpolysize = 0;} else +void setmaterial(mp, cent, ispoly) /* prepare for new material */ register MATREC *mp; FVECT cent; @@ -80,8 +80,8 @@ register FVECT v[]; /* vertex list */ } -static -glu_error(en) /* report a tessellation error as a warning */ +static void +glu_error(en) /* report an error as a warning */ GLenum en; { sprintf(errmsg, "GLU error %s: %s", glu_rout, gluErrorString(en)); @@ -89,14 +89,32 @@ GLenum en; } +static void +myCombine(coords, vertex_data, weight, dataOut) +register GLdouble coords[3]; +GLdouble *vertex_data[4]; +GLfloat weight[4]; +GLdouble **dataOut; +{ + register GLdouble *newvert; + + newvert = (GLdouble *)malloc(3*sizeof(GLdouble)); + if (newvert == NULL) + error(SYSTEM, "out of memory in myCombine"); + VCOPY(newvert, coords); /* no data, just coordinates */ + *dataOut = newvert; +} + + static newtess() /* allocate GLU tessellation object */ { if ((gluto = gluNewTess()) == NULL) error(INTERNAL, "gluNewTess failed"); - gluTessCallback(gluto, GLU_TESS_BEGIN, glBegin); - gluTessCallback(gluto, GLU_TESS_VERTEX, glVertex3dv); + gluTessCallback(gluto, GLU_TESS_BEGIN, (_GLUfuncptr)glBegin); + gluTessCallback(gluto, GLU_TESS_VERTEX, (_GLUfuncptr)glVertex3dv); gluTessCallback(gluto, GLU_TESS_END, glEnd); + gluTessCallback(gluto, GLU_TESS_COMBINE, myCombine); gluTessCallback(gluto, GLU_TESS_ERROR, glu_error); gluTessProperty(gluto, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); } @@ -112,6 +130,7 @@ newquadric() /* allocate GLU quadric structure */ } +int o_face(o) /* convert a face */ register OBJREC *o; { @@ -125,8 +144,8 @@ register OBJREC *o; if (area <= FTINY) return; if (dolights) /* check for source */ - doflatsrc(o->os, cent, norm, area); - setmaterial(o->os, cent, 1); /* set material */ + doflatsrc((MATREC *)o->os, cent, norm, area); + setmaterial((MATREC *)o->os, cent, 1); /* set material */ if (o->oargs.nfargs/3 != curpolysize) { if (curpolysize) glEnd(); curpolysize = o->oargs.nfargs/3; @@ -161,6 +180,7 @@ register OBJREC *o; } +void surfclean() /* clean up surface routines */ { setmaterial(NULL, NULL, 0); @@ -176,6 +196,7 @@ surfclean() /* clean up surface routines */ } +int o_sphere(o) /* convert a sphere */ register OBJREC *o; { @@ -188,9 +209,9 @@ register OBJREC *o; } else if (o->oargs.farg[3] <= FTINY) return; if (dolights) - dosphsrc(o->os, o->oargs.farg, + dosphsrc((MATREC *)o->os, o->oargs.farg, PI*o->oargs.farg[3]*o->oargs.farg[3]); - setmaterial(o->os, o->oargs.farg, 0); + setmaterial((MATREC *)o->os, o->oargs.farg, 0); if (gluqo == NULL) newquadric(); glu_rout = "making sphere"; gluQuadricOrientation(gluqo, @@ -202,10 +223,10 @@ register OBJREC *o; (GLdouble)o->oargs.farg[2]); gluSphere(gluqo, (GLdouble)o->oargs.farg[3], NSLICES, NSTACKS); glPopMatrix(); - rgl_checkerr("creating sphere"); } +int o_cone(o) /* convert a cone or cylinder */ register OBJREC *o; { @@ -215,7 +236,7 @@ register OBJREC *o; iscyl = o->otype==OBJ_CYLINDER | o->otype==OBJ_TUBE; if (o->oargs.nfargs != (iscyl ? 7 : 8)) - objerror(o, "bad # real arguments"); + objerror(o, USER, "bad # real arguments"); if (o->oargs.farg[6] < -FTINY) { o->oargs.farg[6] = -o->oargs.farg[6]; if (iscyl) @@ -230,14 +251,16 @@ register OBJREC *o; objerror(o, USER, "illegal radii"); if (o->oargs.farg[6] <= FTINY && (iscyl || o->oargs.farg[7] <= FTINY)) return; - if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ - o->oargs.farg[6] = 0.; - if (!iscyl && o->oargs.farg[7] < 0.) - o->oargs.farg[7] = 0.; + if (!iscyl) { + if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ + o->oargs.farg[6] = 0.; + if (o->oargs.farg[7] < 0.) + o->oargs.farg[7] = 0.; + } cent[0] = .5*(o->oargs.farg[0] + o->oargs.farg[3]); cent[1] = .5*(o->oargs.farg[1] + o->oargs.farg[4]); cent[2] = .5*(o->oargs.farg[2] + o->oargs.farg[5]); - setmaterial(o->os, cent, 0); + setmaterial((MATREC *)o->os, cent, 0); if (gluqo == NULL) newquadric(); glu_rout = "making cylinder"; gluQuadricOrientation(gluqo, o->otype==OBJ_CUP | o->otype==OBJ_TUBE ? @@ -263,17 +286,17 @@ register OBJREC *o; gluCylinder(gluqo, o->oargs.farg[6], o->oargs.farg[iscyl ? 6 : 7], h, NSLICES, 1); glPopMatrix(); - rgl_checkerr("creating cone"); } +int o_ring(o) /* convert a ring */ register OBJREC *o; { double x1, y1, d; if (o->oargs.nfargs != 8) - objerror(o, "bad # real arguments"); + objerror(o, USER, "bad # real arguments"); if (o->oargs.farg[7] < o->oargs.farg[6]) { register double d = o->oargs.farg[7]; o->oargs.farg[7] = o->oargs.farg[6]; @@ -286,10 +309,10 @@ register OBJREC *o; if (o->oargs.farg[7] - o->oargs.farg[6] <= FTINY) return; if (dolights) - doflatsrc(o->os, o->oargs.farg, o->oargs.farg+3, + doflatsrc((MATREC *)o->os, o->oargs.farg, o->oargs.farg+3, PI*(o->oargs.farg[7]*o->oargs.farg[7] - o->oargs.farg[6]*o->oargs.farg[6])); - setmaterial(o->os, o->oargs.farg, 0); + setmaterial((MATREC *)o->os, o->oargs.farg, 0); if (gluqo == NULL) newquadric(); glu_rout = "making disk"; gluQuadricOrientation(gluqo, GLU_OUTSIDE); @@ -312,5 +335,4 @@ register OBJREC *o; glRotated(d, (GLdouble)x1, (GLdouble)y1, 0.); gluDisk(gluqo, o->oargs.farg[6], o->oargs.farg[7], NSLICES, 1); glPopMatrix(); - rgl_checkerr("creating ring"); }