views:

141

answers:

2

I need to draw a spinning globe using opengl es in android. I think we need to draw a sphere and then apply a texture map on it. If I am correct, we cannot use the utility library glu in Opengl ES for drawing a sphere. I did find some code in objective C, but then I would have to make it work on android.

http://www.iphone4gnew.com/procedural-spheres-in-opengl-es.html

Is there any other way to do this ? I'm no sure how to approach this problem, Could you give me some inputs that would set me looking in the right direction.

Thanks

+2  A: 

You could actually create your own sphere rendering function.

A tesselated sphere is no more then a stack of n cone segments, each approximated with m slices.

This image (courtsey of dglwiki.de) illustrates this: gluSphere construction

(the german text translates to 'If the resolution is to low, the sphere degenerates to other symetric Bodies)

In order to construct the sphere, you'll need to specify the center point, radius, number of stacks and number of slices per stack.

The first pole of your sphere can be any point with a distance of radius from the center point. The vector from this point to the center point defines your sphere's axis of rotation (and thereby the position of the second pole)

Next, you'll need to approximate several equidistant circles of latitude on your sphere around the axis of rotation. The number of circles should be number of stacks -1. Each of these circles should have as much vertices as your desirred number of slices.

Having calculated these, you have enough geometry information to construct your spheres faces.

Begin with a triangle fan originating at one of the poles using the vertices of the first circle. Then, constuct Triangle strips for each pair of neighbouring circles of latitude. The last step is to construct another triangle fan from the second pole to the last of your circles of latitude.

Using this approach, you can generate arbitrary spheres of arbitrary smoothness

sum1stolemyname
Thank you, let me try this out..
Carl
A: 

In addition to what sum1 says, the link you provide to obj-C code is mostly just C, which translates quite nicely to Java/android. The technique provided is very similar to the one sum1 suggests, although the author uses only one fan at the top, then draws the entire remainder of the sphere with a single triangle strip. In addition, his globe is "laying on its side", with the fan at the "East pole" and the other point at the "west pole."

However, you can either use the link you provide as-is, or make the adjustments easily enough.

Olie