X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_geometry.c;h=572b7e318612344e1ea9acadd0cbcbb957541ac2;hb=134051040e95088462463a6bd36c5081d354d0c3;hp=c74cac4837f66bad264d69ce7ea1ba76935c8bac;hpb=ee7bbd68f288bee1bf90734568422cb15cb7723e;p=freeglut diff --git a/src/fg_geometry.c b/src/fg_geometry.c index c74cac4..572b7e3 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -33,6 +33,7 @@ */ +#ifndef GL_ES_VERSION_2_0 /* 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 @@ -42,15 +43,15 @@ * decomposition needed. We use the "first" parameter in glDrawArrays to go * from face to face. */ -static void fghDrawGeometryWire(GLdouble *vertices, GLdouble *normals, GLsizei numFaces, GLsizei numEdgePerFace) +static void fghDrawGeometryWire(GLfloat *vertices, GLfloat *normals, GLsizei numFaces, GLsizei numEdgePerFace) { int i; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - glVertexPointer(3, GL_DOUBLE, 0, vertices); - glNormalPointer(GL_DOUBLE, 0, normals); + glVertexPointer(3, GL_FLOAT, 0, vertices); + glNormalPointer(GL_FLOAT, 0, normals); /* Draw per face (TODO: could use glMultiDrawArrays if available) */ for (i=0; i 0 ) { - GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */ + double local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */ unsigned int stride = ipow(4,--numLevels)*TETRAHEDRON_VERT_ELEM_PER_OBJ; scale /= 2.0 ; for ( i = 0 ; i < TETRAHEDRON_NUM_FACES ; i++ ) @@ -574,7 +576,7 @@ static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLd * The last entry is exactly the same as the first * The sign of n can be flipped to get the reverse loop */ -static void fghCircleTable(GLdouble **sint, GLdouble **cost, const int n, const GLboolean halfCircle) +static void fghCircleTable(GLfloat **sint, GLfloat **cost, const int n, const GLboolean halfCircle) { int i; @@ -582,11 +584,11 @@ static void fghCircleTable(GLdouble **sint, GLdouble **cost, const int n, const const int size = abs(n); /* Determine the angle between samples */ - const GLdouble angle = (halfCircle?1:2)*M_PI/(GLdouble)( ( n == 0 ) ? 1 : n ); + const GLfloat angle = (halfCircle?1:2)*(GLfloat)M_PI/(GLfloat)( ( n == 0 ) ? 1 : n ); /* Allocate memory for n samples, plus duplicate of first entry at the end */ - *sint = malloc(sizeof(GLdouble) * (size+1)); - *cost = malloc(sizeof(GLdouble) * (size+1)); + *sint = malloc(sizeof(GLfloat) * (size+1)); + *cost = malloc(sizeof(GLfloat) * (size+1)); /* Bail out if memory allocation fails, fgError never returns */ if (!(*sint) || !(*cost)) @@ -602,15 +604,15 @@ static void fghCircleTable(GLdouble **sint, GLdouble **cost, const int n, const for (i=1; i0)?1:0]; - r0 = 0.0; + r0 = 0; r1 = sint2[(stacks>0)?1:0]; glBegin(GL_TRIANGLE_FAN); - glNormal3d(0,0,1); - glVertex3d(0,0,radius); + glNormal3f(0,0,1); + glVertex3f(0,0,radf); for (j=slices; j>=0; j--) { - glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 ); - glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius); + glNormal3f(cost1[j]*r1, sint1[j]*r1, z1 ); + glVertex3f(cost1[j]*r1*radf, sint1[j]*r1*radf, z1*radf); } glEnd(); @@ -783,10 +787,10 @@ void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks) for(j=0; j<=slices; j++) { - glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 ); - glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius); - glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 ); - glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius); + glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 ); + glVertex3d(cost1[j]*r1*radf, sint1[j]*r1*radf, z1*radf); + glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 ); + glVertex3d(cost1[j]*r0*radf, sint1[j]*r0*radf, z0*radf); } glEnd(); @@ -804,8 +808,8 @@ void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks) for (j=0; j<=slices; j++) { - glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 ); - glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius); + glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 ); + glVertex3d(cost1[j]*r0*radf, sint1[j]*r0*radf, z0*radf); } glEnd(); @@ -821,19 +825,19 @@ void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks) /* * Draws a wire sphere */ -void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks) +void FGAPIENTRY glutWireSphere(double radius, GLint slices, GLint stacks) { int i,j; /* Adjust z and radius as stacks and slices are drawn. */ - - GLdouble r; - GLdouble x,y,z; + GLfloat radf = (GLfloat)radius; + GLfloat r; + GLfloat x,y,z; /* Pre-computed circle */ - GLdouble *sint1,*cost1; - GLdouble *sint2,*cost2; + GLfloat *sint1,*cost1; + GLfloat *sint2,*cost2; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" ); @@ -854,8 +858,8 @@ void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks) x = cost1[j]; y = sint1[j]; - glNormal3d(x,y,z); - glVertex3d(x*r*radius,y*r*radius,z*radius); + glNormal3f(x,y,z); + glVertex3f(x*r*radf,y*r*radf,z*radf); } glEnd(); @@ -872,10 +876,9 @@ void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks) x = cost1[i]*sint2[j]; y = sint1[i]*sint2[j]; z = cost2[j]; - printf("j(%i):%1.3f\n",j,z); - glNormal3d(x,y,z); - glVertex3d(x*radius,y*radius,z*radius); + glNormal3f(x,y,z); + glVertex3f(x*radf,y*radf,z*radf); } glEnd(); @@ -892,26 +895,26 @@ void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks) /* * Draws a solid cone */ -void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks ) +void FGAPIENTRY glutSolidCone( double base, double height, GLint slices, GLint stacks ) { int i,j; /* Step in z and radius as stacks are drawn. */ - GLdouble z0,z1; - GLdouble r0,r1; + GLfloat z0,z1; + GLfloat r0,r1; - const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); - const GLdouble rStep = base / ( ( stacks > 0 ) ? stacks : 1 ); + const GLfloat zStep = (GLfloat)height / ( ( stacks > 0 ) ? stacks : 1 ); + const GLfloat rStep = (GLfloat)base / ( ( stacks > 0 ) ? stacks : 1 ); /* Scaling factors for vertex normals */ - const GLdouble cosn = ( height / sqrt ( height * height + base * base )); - const GLdouble sinn = ( base / sqrt ( height * height + base * base )); + const GLfloat cosn = ( (GLfloat)height / sqrtf( height * height + base * base )); + const GLfloat sinn = ( (GLfloat)base / sqrtf( height * height + base * base )); /* Pre-computed circle */ - GLdouble *sint,*cost; + GLfloat *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" ); @@ -919,19 +922,19 @@ void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLi /* Cover the circular base with a triangle fan... */ - z0 = 0.0; + z0 = 0; z1 = zStep; - r0 = base; + r0 = (GLfloat)base; r1 = r0 - rStep; glBegin(GL_TRIANGLE_FAN); - glNormal3d(0.0,0.0,-1.0); - glVertex3d(0.0,0.0, z0 ); + glNormal3f(0,0,-1); + glVertex3f(0,0, z0 ); for (j=0; j<=slices; j++) - glVertex3d(cost[j]*r0, sint[j]*r0, z0); + glVertex3f(cost[j]*r0, sint[j]*r0, z0); glEnd(); @@ -943,9 +946,9 @@ void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLi for(j=0; j<=slices; j++) { - glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn); - glVertex3d(cost[j]*r0, sint[j]*r0, z0 ); - glVertex3d(cost[j]*r1, sint[j]*r1, z1 ); + glNormal3f(cost[j]*cosn, sint[j]*cosn, sinn); + glVertex3f(cost[j]*r0, sint[j]*r0, z0 ); + glVertex3f(cost[j]*r1, sint[j]*r1, z1 ); } z0 = z1; z1 += zStep; @@ -958,14 +961,14 @@ void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLi glBegin(GL_TRIANGLES); - glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn); + glNormal3f(cost[0]*sinn, sint[0]*sinn, cosn); for (j=0; j 0 ) ? stacks : 1 ); - const GLdouble rStep = base / ( ( stacks > 0 ) ? stacks : 1 ); + const GLfloat zStep = (GLfloat)height / ( ( stacks > 0 ) ? stacks : 1 ); + const GLfloat rStep = (GLfloat)base / ( ( stacks > 0 ) ? stacks : 1 ); /* Scaling factors for vertex normals */ - const GLdouble cosn = ( height / sqrt ( height * height + base * base )); - const GLdouble sinn = ( base / sqrt ( height * height + base * base )); + const GLfloat cosn = ( (GLfloat)height / sqrtf( height * height + base * base )); + const GLfloat sinn = ( (GLfloat)base / sqrtf( height * height + base * base )); /* Pre-computed circle */ - GLdouble *sint,*cost; + GLfloat *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" ); @@ -1012,8 +1015,8 @@ void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLin for( j=0; j 0 ) ? stacks : 1 ); + GLfloat radf = (GLfloat)radius; + GLfloat z0,z1; + const GLfloat zStep = (GLfloat)height / ( ( stacks > 0 ) ? stacks : 1 ); /* Pre-computed circle */ - GLdouble *sint,*cost; + GLfloat *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" ); @@ -1067,35 +1070,35 @@ void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices /* Cover the base and top */ glBegin(GL_TRIANGLE_FAN); - glNormal3d(0.0, 0.0, -1.0 ); - glVertex3d(0.0, 0.0, 0.0 ); + glNormal3f(0, 0, -1 ); + glVertex3f(0, 0, 0 ); for (j=0; j<=slices; j++) - glVertex3d(cost[j]*radius, sint[j]*radius, 0.0); + glVertex3f(cost[j]*radf, sint[j]*radf, 0); glEnd(); glBegin(GL_TRIANGLE_FAN); - glNormal3d(0.0, 0.0, 1.0 ); - glVertex3d(0.0, 0.0, height); + glNormal3f(0, 0, 1 ); + glVertex3f(0, 0, (GLfloat)height); for (j=slices; j>=0; j--) - glVertex3d(cost[j]*radius, sint[j]*radius, height); + glVertex3f(cost[j]*radf, sint[j]*radf, (GLfloat)height); glEnd(); /* Do the stacks */ - z0 = 0.0; + z0 = 0; z1 = zStep; for (i=1; i<=stacks; i++) { if (i==stacks) - z1 = height; + z1 = (GLfloat)height; glBegin(GL_QUAD_STRIP); for (j=0; j<=slices; j++ ) { - glNormal3d(cost[j], sint[j], 0.0 ); - glVertex3d(cost[j]*radius, sint[j]*radius, z0 ); - glVertex3d(cost[j]*radius, sint[j]*radius, z1 ); + glNormal3f(cost[j], sint[j], 0 ); + glVertex3f(cost[j]*radf, sint[j]*radf, z0 ); + glVertex3f(cost[j]*radf, sint[j]*radf, z1 ); } glEnd(); @@ -1111,18 +1114,18 @@ void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices /* * Draws a wire cylinder */ -void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks) +void FGAPIENTRY glutWireCylinder(double radius, double height, GLint slices, GLint stacks) { int i,j; /* Step in z and radius as stacks are drawn. */ - - GLdouble z = 0.0; - const GLdouble zStep = height / ( ( stacks > 0 ) ? stacks : 1 ); + GLfloat radf = (GLfloat)radius; + GLfloat z = 0; + const GLfloat zStep = (GLfloat)height / ( ( stacks > 0 ) ? stacks : 1 ); /* Pre-computed circle */ - GLdouble *sint,*cost; + GLfloat *sint,*cost; FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" ); @@ -1133,14 +1136,14 @@ void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, for (i=0; i<=stacks; i++) { if (i==stacks) - z = height; + z = (GLfloat)height; glBegin(GL_LINE_LOOP); for( j=0; j