diff --git a/freeglut/freeglut/src/fg_geometry.c b/freeglut/freeglut/src/fg_geometry.c index a24a805..837b4fb 100644 --- a/freeglut/freeglut/src/fg_geometry.c +++ b/freeglut/freeglut/src/fg_geometry.c @@ -117,9 +117,40 @@ static void fghDrawGeometry(GLenum vertexMode, GLdouble *vertices, GLdouble *nor } } -static void fghGenerateGeometryWithEdgeFlag(int numFaces, int numEdgePerFace, GLdouble *vertices, GLubyte *vertIndices, GLdouble *normals, GLboolean *edgeFlags, GLdouble *vertOut, GLdouble *normOut, GLboolean *edgeFlagsOut) +/* triangle decomposition and associated edgeFlags + * be careful to keep winding of all triangles counter-clockwise, + * assuming that input has correct winding... + */ +static GLubyte vertSamp3[3] = {0,1,2}; +static GLubyte vertSamp4[6] = {0,1,2, 0,2,3}; /* quad : 4 input vertices, 6 output (2 triangles) */ +static GLubyte vertSamp5[9] = {0,1,2, 0,2,4, 4,2,3}; /* pentagon: 5 input vertices, 9 output (3 triangles) */ +static GLboolean edgeFlag3[3] = {1,1,1}; /* triangles remain triangles, all edges are external */ +static GLboolean edgeFlag4[6] = {1,1,0, 0,1,1}; +static GLboolean edgeFlag5[9] = {1,1,0, 0,0,1, 0,1,1}; + +static void fghGenerateGeometryWithEdgeFlag(int numFaces, int numEdgePerFaceIn, GLdouble *vertices, GLubyte *vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut, GLboolean *edgeFlagsOut) { - int i,j; + int i,j,numEdgePerFaceOut; + GLubyte *vertSamps = NULL; + GLboolean *edgeFlags = NULL; + switch (numEdgePerFaceIn) + { + case 3: + vertSamps = vertSamp3; + edgeFlags = edgeFlag3; + numEdgePerFaceOut = 3; /* 3 output vertices for each face */ + break; + case 4: + vertSamps = vertSamp4; + edgeFlags = edgeFlag4; + numEdgePerFaceOut = 6; /* 6 output vertices for each face */ + break; + case 5: + vertSamps = vertSamp5; + edgeFlags = edgeFlag5; + numEdgePerFaceOut = 9; /* 9 output vertices for each face */ + break; + } /* * Build array with vertices from vertex coordinates and vertex indices * Do same for normals. @@ -129,11 +160,12 @@ static void fghGenerateGeometryWithEdgeFlag(int numFaces, int numEdgePerFace, GL for (i=0; i