# OpenGL es sphere tutorial

• 10-07-2011, 08:06 PM
grebwed
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.

Many thanks in advance.

Drew
• 01-06-2012, 03:25 PM
leeubck
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.
• 04-23-2012, 02:36 AM
debinair
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);
• 05-09-2012, 10:55 PM
abhijeet9888
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.