# Thread: OpenGL es sphere tutorial

1. ## OpenGL es sphere tutorial

Hello,

I am pretty new to opengl es. Recently, I figured out how to create a circle in opengl-es 1.x. I really wnat to create sphere, but I am not really sure how to. Is there any tutorial out there that anyone could point me to?

Would you make a sphere using only triangle_strips, or triangle strips and triangle_fans for the poles?

Also, I am trying to make this for android.

Drew

2. ## Re: OpenGL es sphere tutorial

I wanted to try this openGL, It will be great if there is no more need of plug ins. Hoping to find tutorials on this too. Thanks.

3. ## Re: OpenGL es sphere tutorial

There is no specific API for this. You have to draw using existing calls only.
However, You can draw sphere by using polar coordinates of circle.

GLfloat vertices[720];
for (int i = 0; i < 720; i += 2) {
// x value
vertices[i] = (cos(DEGREES_TO_RADIANS(i/2)) * 0.4); // x=r *cos(theta)
// y value
vertices[i+1] = (sin(DEGREES_TO_RADIANS(i/2)) * 0.6);// y= r*sin(theta)
}
glVertexAttribPointer(0,2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, 360);

4. ## Re: OpenGL es sphere tutorial

Hi,
Drawing a sphere in opengl es 1/2 is quite difficult . First of all there is no built in function for this and secondly you have to draw using basic primitives only viz. triangle,point,line.

Method mentioned by debinair is applicable for circles only. Sphere being a 3D object you need Z component as well.

So you will need polar co-ordinates of sphere first of all. They are :

Vertices[0]= r* sin(thita)*cos(fy);
Vertices[1]= r*sin(thita)*sin(fy);
Vertices[2]= r*cos(thita);

Just like we had thita for a circle we have an additional "fy" here. It goes from 0 to pi radians. (And thita from 0 to 2*pi).

Consider your sphere to be made up of slices , you have to draw each slice using above mentioned formula.
Give it a shot I have already done it successfully.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•