12,406,124 members (40,597 online)
Rate this:
See more:
I want to draw a cylinder using only a one circle. But I don't know how should I do it. If anybody knows this, please explain me it. Thanks.
Posted 23-Apr-12 18:31pm
Steve Echols 24-Apr-12 1:08am

Are you using glut.h? Google gluCylinder.
Jeremy Shin Woo 24-Apr-12 1:12am

yes. I'm using glut.h
Steve Echols 24-Apr-12 1:16am

There are tons of examples on how to draw cylinders with opengl on the web. NeHe is very useful (or was back when I was doing openGL :))

Jeremy Shin Woo 24-Apr-12 1:21am

I know how draw a cylinder in openGL. But I want to draw it using only one circle
Steve Echols 24-Apr-12 1:32am

Well, you can't draw circles in openGL, only simulate them using primitives like line strips, so I'm not sure what you mean by "one circle". Do you you mean "one for loop" iterating around the circle and drawing triangles or quads? You should be able to do this with a GL_QUAD_STRIP.
enhzflep 24-Apr-12 1:43am

Another option is to use GL_TRIANGLE_FAN - it certainly seems like the 'goer' for capping the ends.
Steve Echols 24-Apr-12 1:47am

True, true. Wasn't sure if he wanted a hollow tube or a capped cylinder.
Jeremy Shin Woo 24-Apr-12 2:16am

I could draw a circle.

int i, j,k;
vertices = new float[3*(p+1)*(q+1)]; // Dynamic array allocation with new value of p and q.

glVertexPointer(3, GL_FLOAT, 0, vertices);
glClear(GL_COLOR_BUFFER_BIT);

gluLookAt (0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

glColor3f(0.0, 0.0, 0.0);

// Rotate scene.
glRotatef(Zangle, 0.0, 0.0, 1.0);
glRotatef(Yangle, 0.0, 1.0, 0.0);
glRotatef(Xangle, 1.0, 0.0, 0.0);

// Fill the vertex array.
fillVertexArray();

// Make the approximating triangular mesh.
for(j = 0; j < q; j++)

{
float t = 0,h = 0; // Angle parameter.
int i;
for(i = 0; i <= p; i++)
{
glArrayElement( (j+1)*(p+1) + i );
glArrayElement( j*(p+1) + i );
}
glEnd();*/
glBegin(GL_LINE_LOOP);

for(i = 0; i < numVertices; ++i)
{
glVertex3f(X+ R * cos(t), Y + R * sin(t), 0);
t += 2 * PI / numVertices;

}
glEnd();

}

glutSwapBuffers();

This the code of its.But I can't draw a cylinder using this circle
Bhathiyaj 24-Apr-12 2:17am

I'm having the same question and let me explain it well. (since i'm having the same issue, i don't think i'm hijacking the thread.) What I want is to draw a cylinder. But I have a restriction given, that I have to draw it only using a circle's code. (may be by duplicating it through a line.) Any help on how to achieve this? Thanks in advance.

Top Experts
Last 24hrsThis month
 OriginalGriff 366 Karthik Bangalore 179 BillWoodruff 165 ppolymorphe 144 Richard Deeming 125
 OriginalGriff 7,747 ppolymorphe 3,380 Karthik Bangalore 3,321 Richard MacCutchan 2,472 F-ES Sitecore 2,300