+ glPushAttrib(GL_POLYGON_BIT);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ glutSolidCube(sz);
+ glPopAttrib();
+}
+
+static void draw_cylinder(float rbot, float rtop, float height, int slices, int stacks)
+{
+ int i, j, k, gray;
+ float x, y, z, s, t, u, v, theta, phi, sintheta, costheta, sinphi, cosphi, rad;
+ float du = 1.0f / (float)slices;
+ float dv = 1.0f / (float)stacks;
+
+ rad = rbot - rtop;
+ phi = mglut_atan((rad < 0 ? -rad : rad) / height);
+ mglut_sincosf(phi, &sinphi, &cosphi);
+
+ glBegin(GL_QUADS);
+ for(i=0; i<stacks; i++) {
+ v = i * dv;
+ for(j=0; j<slices; j++) {
+ u = j * du;
+ for(k=0; k<4; k++) {
+ gray = k ^ (k >> 1);
+ s = gray & 2 ? u + du : u;
+ t = gray & 1 ? v + dv : v;
+ rad = rbot + (rtop - rbot) * t;
+ theta = s * PI * 2.0f;
+ mglut_sincosf(theta, &sintheta, &costheta);
+
+ x = sintheta * cosphi;
+ y = costheta * cosphi;
+ z = sinphi;
+
+ glColor3f(s, t, 1);
+ glTexCoord2f(s, t);
+ glNormal3f(x, y, z);
+ glVertex3f(sintheta * rad, costheta * rad, t * height);
+ }
+ }
+ }
+ glEnd();
+}
+
+void glutSolidCone(float base, float height, int slices, int stacks)
+{
+ draw_cylinder(base, 0, height, slices, stacks);
+}
+
+void glutWireCone(float base, float height, int slices, int stacks)
+{
+ glPushAttrib(GL_POLYGON_BIT);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ glutSolidCone(base, height, slices, stacks);
+ glPopAttrib();
+}
+
+void glutSolidCylinder(float rad, float height, int slices, int stacks)
+{
+ draw_cylinder(rad, rad, height, slices, stacks);
+}
+
+void glutWireCylinder(float rad, float height, int slices, int stacks)
+{
+ glPushAttrib(GL_POLYGON_BIT);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ glutSolidCylinder(rad, height, slices, stacks);
+ glPopAttrib();