Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to draw cone using OpenGL ES I have gone through many links to draw cylinder but I don't have any idea or approach to draw the cylinder. I've seen the gluCylinder function for OpenGL, but no equivalent function in OpenGL-ES.

i tried the below code

float radius, halfLength;
int slices;
for(int i=0; i<slices; i++) {
    float theta = ((float)i)*2.0*M_PI;
    float nextTheta = ((float)i+1)*2.0*M_PI;
    /*vertex at middle of end */ glVertex3f(0.0, halfLength, 0.0);
    /*vertices at edges of circle*/ glVertex3f(radius*cos(theta), 
    halfLength, radius*sin(theta));
    glVertex3f (radius*cos(nextTheta), halfLength, radius*sin(nextTheta));
    /* the same vertices at the bottom of the cylinder*/
    glVertex3f (radius*cos(nextTheta), -halfLength, radius*sin(nextTheta));
    glVertex3f(radius*cos(theta), -halfLength, radius*sin(theta));
    glVertex3f(0.0, -halfLength, 0.0);
share|improve this question

closed as too localized by Byte56, bummzack, Sean Middleditch, Trevor Powell, Josh Petrie Mar 28 '13 at 15:39

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Aron Boguta's answer is excellent. I would just want to comment that if you're trying to do this for practical reasons (you will want to have more complex geometry in Open GL), it's best if you at least find a library that lets you load meshes made with specialized software (like 3ds Max or Blender). Usually Obj+Mat or fbx formats are supported by many such libraries (and the 3d softwares as well). Example:… – Shivan Dragon Mar 20 '13 at 12:54
I think this is a "can I have the code" question. – Byte56 Mar 20 '13 at 13:52
up vote 1 down vote accepted

Basically the formula would be as follows :

(assuming Y points up)

you need to declare "slices", "HEIGHT", r

x- origin of the bottem circle on X axis

y- origin of the bottem circle on Y axis

z- origin of the bottem circle on Z axis

// bottom circle
for(int i=0, float alpha=0; i<slices; i++) glVertex3f(x + cos((float)i/slices * 2 *PI)*r,
y, z+sin((float)i/slices * 2 * PI)*r);

//top circle
glVertex3f(x,y + HEIGHT,z);
for(int i=0, float alpha=0; i<slices; i++) glVertex3f(x + cos((float)i/slices * 2 *PI)*r,
y+ HEIGHT, z+sin((float)i/slices * 2 * PI)*r);

// the rest
for(int i=0, float alpha=0; i<slices; i++) 
   glVertex3f(x + cos((float)i/slices * 2 *PI)*r,y, z+sin((float)i/slices * 2 * PI)*r);
   glVertex3f(x + cos((float)i/slices * 2 *PI)*r,y+ HEIGHT, z+sin((float)i/slices * 2 *      PI)*r);

This should be just fine

share|improve this answer
this code is not working in opengles 1.1 , it gives error on glBegin and glEnd Error: Implicit declaration of function 'glBegin' is invalid in C99 – DattatrayD Mar 20 '13 at 13:04
Which line causes the error? Or is that whenever you use glBegin it pops up something? – AB. Mar 20 '13 at 14:23
Btw check this answer : And more precisely answer provided by user1401452. Is that your problem? – AB. Mar 20 '13 at 15:04
One of the limitations of opengl ES is that you are not permitted to use certain functions that computationally expensive. What you could do is precompute your cylinder (which is the recommended method) – Sparksis Mar 20 '13 at 17:33
geBegin and glEnd Pops message symbol not found, i am using this code in cocos3d environment – DattatrayD Mar 21 '13 at 6:55

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