From: Diederick Niehorster Date: Sat, 28 Apr 2012 13:29:49 +0000 (+0000) Subject: Wire Torus now ported X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=572476eca1c2dfac92fe90ec5c8f0d397a0a4c1f;p=freeglut Wire Torus now ported solid torus now as triangle strips, but still need to finish port git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1267 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 28d2c73..8926dcf 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -1296,7 +1296,7 @@ static void fghSphere( double radius, GLint slices, GLint stacks, GLboolean useW { free(stackIdx); free(sliceIdx); - fgError("Failed to allocate memory in fghGenerateSphere"); + fgError("Failed to allocate memory in fghSphere"); } /* generate for each stack */ @@ -1356,7 +1356,7 @@ static void fghSphere( double radius, GLint slices, GLint stacks, GLboolean useW if (!(stripIdx)) { free(stripIdx); - fgError("Failed to allocate memory in fghGenerateSphere"); + fgError("Failed to allocate memory in fghSphere"); } /* top stack */ @@ -1443,7 +1443,7 @@ static void fghCone( double base, double height, GLint slices, GLint stacks, GLb { free(stackIdx); free(sliceIdx); - fgError("Failed to allocate memory in fghGenerateCone"); + fgError("Failed to allocate memory in fghCone"); } /* generate for each stack */ @@ -1498,7 +1498,7 @@ static void fghCone( double base, double height, GLint slices, GLint stacks, GLb if (!(stripIdx)) { free(stripIdx); - fgError("Failed to allocate memory in fghGenerateCone"); + fgError("Failed to allocate memory in fghCone"); } /* top stack */ @@ -1574,7 +1574,7 @@ static void fghCylinder( double radius, double height, GLint slices, GLint stack { free(stackIdx); free(sliceIdx); - fgError("Failed to allocate memory in fghGenerateCylinder"); + fgError("Failed to allocate memory in fghCylinder"); } /* generate for each stack */ @@ -1629,7 +1629,7 @@ static void fghCylinder( double radius, double height, GLint slices, GLint stack if (!(stripIdx)) { free(stripIdx); - fgError("Failed to allocate memory in fghGenerateCylinder"); + fgError("Failed to allocate memory in fghCylinder"); } /* top stack */ @@ -1688,6 +1688,104 @@ static void fghCylinder( double radius, double height, GLint slices, GLint stack free(normals); } +static void fghTorus( double dInnerRadius, double dOuterRadius, GLint nSides, GLint nRings, GLboolean useWireMode ) +{ + int i,j,idx, nVert; + GLfloat *vertices, *normals; + + /* Generate vertices and normals */ + fghGenerateTorus((GLfloat)dInnerRadius,(GLfloat)dOuterRadius,nSides,nRings, &vertices,&normals,&nVert); + + if (nVert==0) + /* nothing to draw */ + return; + + if (useWireMode) + { + GLushort *sideIdx, *ringIdx; + /* First, generate vertex index arrays for drawing with glDrawElements + * We have a bunch of line_loops to draw each side, and a + * bunch for each ring. + */ + + ringIdx = malloc(nRings*nSides*sizeof(GLushort)); + sideIdx = malloc(nSides*nRings*sizeof(GLushort)); + if (!(ringIdx) || !(sideIdx)) + { + free(ringIdx); + free(sideIdx); + fgError("Failed to allocate memory in fghTorus"); + } + + /* generate for each ring */ + for( j=0,idx=0; j