void Draw_Cylinder (int numMajor, int numMinor, float height, float radius)
{
int i, j;
GLfloat x, y, z0, z1;
const float M_PI = 3.141593;
double majorStep = height / numMajor, a;
double minorStep = 2.0 * M_PI / numMinor;
for (i = 0; i < numMajor; ++i) {
z0 = 0.5 * height - i * majorStep;
z1 = z0 - majorStep;
}
glBegin (GL_TRIANGLE_STRIP);
for (j = 0; j <= numMinor; ++j) { // Cylinder Sides
a = j * minorStep;
x = radius * cos(a);
y = radius * sin(a);
glNormal3f (x / radius, y / radius, 0.0);
glTexCoord2f (j / (GLfloat)numMinor, i / (GLfloat)numMajor);
glVertex3f (x, y, z0);
glNormal3f (x / radius, y / radius, 0.0);
glTexCoord2f (j / (GLfloat)numMinor, (i + 1) / (GLfloat)numMajor);
glVertex3f (x, y, z1);
}
glEnd ();
glColor3f (1.0, 0.6, 0.2);
glBegin (GL_POLYGON); // Cylinder Bottom - Orange Circle
glNormal3f (0.0, 0.0, -1.0);
for (j = 0; j <= numMinor; ++j) {
a = j * minorStep;
x = radius * cos(a);
y = radius * sin(a);
glVertex3f (x, y, z0);
}
glEnd ();
glColor3f (1.0, 0.6, 1.0);
glBegin (GL_POLYGON); // Cylinder Top - Pink Circle
glNormal3f (0.0, 0.0, 1.0);
for (j = 0; j <= numMinor; ++j) {
a = j * -minorStep;
x = radius * cos(a);
y = radius * sin(a);
glVertex3f (x, y, z1);
}
glEnd ();
return;
}