torus ported. All shapes drawn with glDrawArrays and glDrawElements now.

Next is to use the same drawing functions for all shapes, all those with
circles still have their own now


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1269 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2012-04-28 17:01:44 +00:00
parent 93e05f42de
commit a01a0426e7

View File

@ -1757,22 +1757,39 @@ static void fghTorus( double dInnerRadius, double dOuterRadius, GLint nSides, GL
GLushort *stripIdx; GLushort *stripIdx;
/* Allocate buffers for indices, bail out if memory allocation fails */ /* Allocate buffers for indices, bail out if memory allocation fails */
//stripIdx = malloc((slices+1)*2*(stacks+2)*sizeof(GLushort)); stripIdx = malloc((nRings+1)*2*nSides*sizeof(GLushort));
if (!(stripIdx)) if (!(stripIdx))
{ {
free(stripIdx); free(stripIdx);
fgError("Failed to allocate memory in fghTorus"); fgError("Failed to allocate memory in fghTorus");
} }
for( i=0, idx=0; i<nSides; i++ )
{
int ioff = 1;
if (i==nSides-1)
ioff = -i;
for( j=0; j<nRings; j++, idx+=2 )
{
int offset = j * nSides + i;
stripIdx[idx ] = offset;
stripIdx[idx+1] = offset + ioff;
}
/* repeat first to close off shape */
stripIdx[idx ] = i;
stripIdx[idx+1] = i + ioff;
idx +=2;
}
/* draw */ /* draw */
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices); glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals); glNormalPointer(GL_FLOAT, 0, normals);
/*draw stacks*/ for (i=0; i<nSides; i++)
//for (i=0; i<stacks+2; i++) glDrawElements(GL_TRIANGLE_STRIP,(nRings+1)*2,GL_UNSIGNED_SHORT,stripIdx+i*(nRings+1)*2);
// glDrawElements(GL_TRIANGLE_STRIP,(slices+1)*2,GL_UNSIGNED_SHORT,stripIdx+i*(slices+1)*2);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
@ -1869,46 +1886,9 @@ void FGAPIENTRY glutWireTorus( double dInnerRadius, double dOuterRadius, GLint n
*/ */
void FGAPIENTRY glutSolidTorus( double dInnerRadius, double dOuterRadius, GLint nSides, GLint nRings ) void FGAPIENTRY glutSolidTorus( double dInnerRadius, double dOuterRadius, GLint nSides, GLint nRings )
{ {
GLfloat *vertex, *normal;
int i, j, nVert;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" ); FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
fghTorus(dInnerRadius, dOuterRadius, nSides, nRings, FALSE);
fghGenerateTorus(
dInnerRadius, dOuterRadius, nSides, nRings, /* input */
&vertex, &normal, &nVert /* output */
);
for( i=0; i<nSides; i++ )
{
int offset;
int ioff = 3;
if (i==nSides-1)
ioff = -i*3;
glBegin( GL_TRIANGLE_STRIP );
for( j=0; j<nRings; j++ )
{
offset = 3 * ( j * nSides + i ) ;
glNormal3fv( normal + offset );
glVertex3fv( vertex + offset );
glNormal3fv( normal + offset + ioff );
glVertex3fv( vertex + offset + ioff );
}
/* repeat first to close off shape */
offset = 3 * i;
glNormal3fv( normal + offset );
glVertex3fv( vertex + offset );
glNormal3fv( normal + offset + ioff );
glVertex3fv( vertex + offset + ioff );
glEnd();
}
free ( vertex ) ;
free ( normal ) ;
} }
#endif /* EGL_VERSION_1_0 */ #endif /* EGL_VERSION_1_0 */