2

i am new opengl learner. i know there is build in function to draw cylinder in glut something like

GLUquadricObj *quadratic;
quadratic=gluNewQuadric();
gluCylinder(quadratic,0.6f,0.6f,1.5f,20,20);

However, is there any other way to draw cylinder using glBegin(GL_POLYGON) and glvertex3d, i am not quite clear about the algorithm behind, please help.

1
  • 1
    By the way, never ever use GL_POLYGON. A bunch of triangles (GL_TRIANGLES, or GL_QUADS if you really want) will do, too and doesn't require you to use an individual glBegin/glEnd block (or an individual draw call) for each face. Mar 17, 2012 at 0:54

1 Answer 1

4

Use sin/cos to trace around a circle in segments. Extend those segments upwards with 2 triangles. Then connect them to close the ends.

You may be able to find the source online for freeglut. Here's some Java code I found: http://massapi.com/source/lwjgl-source-2.7.1/src/java/org/lwjgl/util/glu/Cylinder.java.html

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.