X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_geometry.c;h=c74cac4837f66bad264d69ce7ea1ba76935c8bac;hb=ee7bbd68f288bee1bf90734568422cb15cb7723e;hp=77b09a790678529eba45d7c9afc85e7f4be1cd58;hpb=46d1878cf7d5cee323caf1c7e65f81f20fcf91eb;p=freeglut diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 77b09a7..c74cac4 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -33,169 +33,88 @@ */ -/* General function for drawing geometry. As for all geometry we have no - * redundancy (or hardly any in the case of cones and cylinders) in terms - * of the vertex/normal combinations, we just use glDrawArrays. - * useWireMode controls the drawing of solids (false) or wire frame - * versions (TRUE) of the geometry you pass +/* General functions for drawing geometry + * Solids are drawn by glDrawArrays if composed of triangles, or by + * glDrawElements if consisting of squares or pentagons that were + * decomposed into triangles (some vertices are repeated in that case). + * WireFrame drawing will have to be done per face, using GL_LINE_LOOP and + * issuing one draw call per face. Always use glDrawArrays as no triangle + * decomposition needed. We use the "first" parameter in glDrawArrays to go + * from face to face. */ -static void fghDrawGeometry(GLdouble *vertices, GLdouble *normals, GLboolean *edgeFlags, GLsizei numVertices, GLsizei numFaces, GLsizei numEdgePerFace, GLboolean useWireMode) +static void fghDrawGeometryWire(GLdouble *vertices, GLdouble *normals, GLsizei numFaces, GLsizei numEdgePerFace) { -# ifdef FREEGLUT_GLES1 - /* Solid drawing is the same for OpenGL 1.x and OpenGL ES 1.x, just - * no edge flags for ES. - * WireFrame drawing will have to be done per face though, using - * GL_LINE_LOOP and issuing one draw call per face. For triangles, - * we use glDrawArrays directly on the vertex data for each face, - * while for shapes that are composed of quads or pentagons, we use - * glDrawElements with index vector {0,1,2,5} or {0,1,2,8,5}, - * respectively. - * We use the first parameter in glDrawArrays or glDrawElements to - * go from face to face. - */ - if (useWireMode) - { - /* setup reading the right elements from vertex array */ - GLubyte vertIdx4[4] = {0,1,2,5}; - GLubyte vertIdx5[5] = {0,1,2,8,5}; - GLubyte *indices = NULL; - int vertStride, i, j; - - switch (numEdgePerFace) - { - case 3: - vertStride = 3; /* there are 3 vertices for each face in the array */ - break; - case 4: - indices = vertIdx4; - vertStride = 6; /* there are 6 vertices for each face in the array */ - break; - case 5: - indices = vertIdx5; - vertStride = 9; /* there are 9 vertices for each face in the array */ - break; - } - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - glVertexPointer(3, GL_DOUBLE, 0, vertices); - glNormalPointer(GL_DOUBLE, 0, normals); - - if (numEdgePerFace==3) - for (i=0; i 0 ) ? stacks : 1 ); - const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 ); + const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); + const GLdouble rStep = base / ( ( stacks > 0 ) ? stacks : 1 ); /* Scaling factors for vertex normals */ - const double cosn = ( height / sqrt ( height * height + base * base )); - const double sinn = ( base / sqrt ( height * height + base * base )); + const GLdouble cosn = ( height / sqrt ( height * height + base * base )); + const GLdouble sinn = ( base / sqrt ( height * height + base * base )); /* Pre-computed circle */ - double *sint,*cost; + GLdouble *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" ); - fghCircleTable(&sint,&cost,-slices); + fghCircleTable(&sint,&cost,-slices,FALSE); /* Cover the circular base with a triangle fan... */ @@ -1039,24 +985,24 @@ void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLin /* Step in z and radius as stacks are drawn. */ - double z = 0.0; - double r = base; + GLdouble z = 0.0; + GLdouble r = base; - const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); - const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 ); + const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); + const GLdouble rStep = base / ( ( stacks > 0 ) ? stacks : 1 ); /* Scaling factors for vertex normals */ - const double cosn = ( height / sqrt ( height * height + base * base )); - const double sinn = ( base / sqrt ( height * height + base * base )); + const GLdouble cosn = ( height / sqrt ( height * height + base * base )); + const GLdouble sinn = ( base / sqrt ( height * height + base * base )); /* Pre-computed circle */ - double *sint,*cost; + GLdouble *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" ); - fghCircleTable(&sint,&cost,-slices); + fghCircleTable(&sint,&cost,-slices,FALSE); /* Draw the stacks... */ @@ -1107,16 +1053,16 @@ void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices /* Step in z and radius as stacks are drawn. */ - double z0,z1; - const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); + GLdouble z0,z1; + const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); /* Pre-computed circle */ - double *sint,*cost; + GLdouble *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" ); - fghCircleTable(&sint,&cost,-slices); + fghCircleTable(&sint,&cost,-slices,FALSE); /* Cover the base and top */ @@ -1171,16 +1117,16 @@ void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, /* Step in z and radius as stacks are drawn. */ - double z = 0.0; - const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); + GLdouble z = 0.0; + const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); /* Pre-computed circle */ - double *sint,*cost; + GLdouble *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" ); - fghCircleTable(&sint,&cost,-slices); + fghCircleTable(&sint,&cost,-slices,FALSE); /* Draw the stacks... */ @@ -1226,10 +1172,10 @@ void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, */ void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings ) { - double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi; - double *vertex, *normal; + GLdouble iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi; + GLdouble *vertex, *normal; int i, j; - double spsi, cpsi, sphi, cphi ; + GLdouble spsi, cpsi, sphi, cphi ; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" ); @@ -1237,13 +1183,13 @@ void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLi if ( nRings < 1 ) nRings = 1; /* Allocate the vertices array */ - vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings ); - normal = (double *)calloc( sizeof(double), 3 * nSides * nRings ); + vertex = (GLdouble *)calloc( sizeof(GLdouble), 3 * nSides * nRings ); + normal = (GLdouble *)calloc( sizeof(GLdouble), 3 * nSides * nRings ); glPushMatrix(); - dpsi = 2.0 * M_PI / (double)nRings ; - dphi = -2.0 * M_PI / (double)nSides ; + dpsi = 2.0 * M_PI / (GLdouble)nRings ; + dphi = -2.0 * M_PI / (GLdouble)nSides ; psi = 0.0; for( j=0; j