PDA

View Full Version : help!!how to draw a cylinder by Glut or other simple methods?



10-30-2001, 10:33 AM
hi,all.
i want to draw a circinal table which consists of cylinders.
can i draw that in a simple ways?
thanks a lot first.

Dong Ke
10-30-2001, 03:58 PM
It seems that you have GLUT. Try to modify the glutSolidCone procedure of it. Notice its params? It has only a base param for the radius of the bottom. Yes, add another param to it to specify the radius of the top. That's easy.

Dong Ke
10-30-2001, 04:02 PM
Oh I forgot. This can only make a cylinder without top and bottom, which is definitely not suitable for your round table. It seems no simple way to make it. Try make polygons instead then.

10-30-2001, 04:31 PM
Perhaps you should look into the functions

gluDisk

and

gluCylinder

and combine them in the appropriate manner

10-30-2001, 05:15 PM
some very simple code to do it
GLUquadricObj* quad= gluNewQuadric();
void drawCylinder(float width, float height)
{
glColor3f(1,0,0);

gluCylinder(quad,width,width, height,20,20);
glColor3f(0,1,0);
gluDisk(quad,0,width,20,20);
glTranslatef(0,0, height);
glColor3f(0,0,1);
gluDisk(quad,0,width,20,20);

}

now remember to delete that quadric object and you are set... until you need texturing

in which case you just call

gluQuadricTexture(GLUquadricObj *quadObject,
GLboolean textureCoords)

with GL_TRUE as the second param

good luck

10-31-2001, 01:14 PM
i worked it out.
It's very kind of you.Dong Ke and mr x.
thanx a lot.