Hi,

I am looking for some source code in C to draw a cylinder and cone using OpenGL (without GLU routines).

Can someone help?

Many thanks!

Printable View

- 11-17-2005FabCone/Cylinder source
Hi,

I am looking for some source code in C to draw a cylinder and cone using OpenGL (without GLU routines).

Can someone help?

Many thanks! - 11-18-2005cwr
Wouldn't the obvious be to look at the GLU routines source and see how it's done?

- 11-18-2005sand_man
are glu sources available? I suppose you can download the Mesa source but I'm not sure if that includes the glu library or not (I suppose it would).

- 11-21-2005Fab
I had a quick look but could not find the source for this. I thought it would be easier if someone had the snippet of code I needed.

Thanks anyway - 11-22-2005Salem
What are you really looking for - the basic math which describes the surface of those objects?

- 11-22-2005Fab
I have actualy found what I was looking for.

For the cylinder's side for instance:

Code:`float hl = length * 0.5f;`

float a = 0.0f;

float step = Math::TWO_PI / (float)numSteps;

glBegin(GL_TRIANGLE_STRIP);

for (int i = 0; i < numSteps; ++i)

{

float x = Math::Cos(a) * radius;

float y = Math::Sin(a) * radius;

glVertex3f(x,y,-hl);

glVertex3f(x,y, hl);

a += step;

}

glEnd();