Click here to Skip to main content
13,096,798 members (84,628 online)
Rate this:
Please Sign up or sign in to vote.
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);

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


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.

// 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 );

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




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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100