OpenGL es sphere tutorial


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.


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
glVertexAttribPointer(0,2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, 360);

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
Vertices[2]= r

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.