Theory (PDF)
Coding (web page)
Solutions
For example, to generate a cylinder, you could do something like the following:
nslices = 12;
dth = 360/nslices; // work with 30 degree slices
float topVertex[nslices][3];
float botVertex[nslices][3];
// compute vertices
for (n=0; n!=nslices; n++) {
theta = n*dth;
// vertices defining bottom ring
botVertex[n][0] = radius*cos(theta);
botVertex[n][1] = 0;
botVertex[n][2] = radius*sin(theta);
// vertices defining top ring
topVertex[n][0] = radius*cos(theta);
topVertex[n][1] = 0;
topVertex[n][2] = radius*sin(theta);
}
// draw using these vertices
for (n=0; n!=nslices; n++) {
n2 = (n+1) % nslices; // next vertex (with wrap-around)
glBegin(GL_LINE_LOOP);
glVertex3fv( botVertex[n] );
glVertex3fv( botVertex[n2] );
glVertex3fv( topVertex[n2] );
glVertex3fv( topVertex[n] );
glEnd();
}