X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_geometry.c;h=7880381e3cb2b9b0f31cbce9e2a11db86d6a292d;hb=82d2fc3b7a46dc2d1f69de86cfa61fb572d6471f;hp=28d2c730d820f1e517fc53620d7d52202b2e9882;hpb=3dbdb2176419cd2dabb3c19e1b24568bdc96be4e;p=freeglut diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 28d2c73..7880381 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,121 @@ 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