Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
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 19:31pm
Comments
Steve Echols at 24-Apr-12 1:08am
   
Are you using glut.h? Google gluCylinder.
Jeremy Shin Woo at 24-Apr-12 1:12am
   
yes. I'm using glut.h
Steve Echols at 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 :))
 
http://nehe.gamedev.net/tutorial/quadrics/20001/
Jeremy Shin Woo at 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 at 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 at 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 at 24-Apr-12 1:47am
   
True, true. Wasn't sure if he wanted a hollow tube or a capped cylinder.
Jeremy Shin Woo at 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);
 
glLoadIdentity();
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 at 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
0 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2014
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