How to texture a sphere correctly?

I think I am raising an amateur question.

I don’t know how to map a texture onto a sphere in a correct way. I’ve tried to do so but the sphere looks strange.

It will be much kind of you if you refer to my Pool3D project at http://zone999.top263.net/Pool3D.zip Please help me to texture the balls correctly.

Thanx so much.

[This message has been edited by Dong Ke (edited 10-29-2001).]

Couldn’t follow your link - could you post a URL for a screenshot showing the problem?

Short answer (which you’re not going to like): it is fundamentally and provably impossible to texture a sphere mesh “correctly” with a single texture image wrapped cylindrically around it. You’ll get squishing and discontinuities at the top and bottom. For pool balls, though, you should be able to arrange your textures to have blocks of solid colour at the top and bottom, and these problems can be made invisible.

http://www.spheregames.com/sge/SkyDomesPDF.zip

contains an article on Sky Domes and Spheres which should be helpful even when the sphere is scaled down to billiard ball size.

Originally posted by MikeC:
[b]Couldn’t follow your link - could you post a URL for a screenshot showing the problem?

Short answer (which you’re not going to like): it is fundamentally and provably impossible to texture a sphere mesh “correctly” with a single texture image wrapped cylindrically around it. You’ll get squishing and discontinuities at the top and bottom. For pool balls, though, you should be able to arrange your textures to have blocks of solid colour at the top and bottom, and these problems can be made invisible.[/b]

I think that you know exactly what my problem is. I set the glTexCoord param to gl_sphere_map, but this seems not the right thing. The center of the texture keeps facing towards me when I rotate the pool. I think it will be OK if only I can “wrap a single texture image cylindrically around it”. But even this I can’t make it. Please help.

By the way, try zone999.top263.net.cn instead.

Thank you so much.

Sphere mapping is something completely different, it is used for reflection. You have to specify the texture coordinates manually.

for(j = -90; j < 90; j+=step)
{
glBegin(GL_TRIANGLE_STRIP);
for(i = 0; i < 360; i+=step)
{
glTexCoord2f((float)i/360, (float)(j+90)/180);
glVertex3f(sin(j)*sin(i), sin(j)*cos(i), cos(j));
glTexCoord2f((float)i/360, (float)(j+step+90)/180);
glVertex3f(sin(j+step)*sin(i), sin(j+step)*cos(i+step), cos(j+step));
}
}

This is only pseudocode, you have to supply the angles in radians instead of degrees, but the code is much more readable when radians are used.

How the vertices are generated is not so important, important is that the texture coordinates are equal to the longitude/latitude coordinates of the sphere, you only have to normalize them from the [0…360] (or [-90…90]) range to the texcoord range of [0…1].

It is absolutely normal that the texture image gets dissorted with this method because it is impossible to texture a sphere with a flat map correctly (try to wrap a sheet of paper around a ball…).

The solution is to correct this in the texture map. In your case, as MikeC said, arrange the maps so that a solid color block is at the top and bottom of the sphere.

Thank you so much for your kind help!

The Sky Domes PDF helped me a lot. I’m now knowing what sphere texture mapping is. I’m trying to correct it.

Thanx again.

Another idea is to try a geosphere which looks like a soccer ball and neatly avoids polar distortion in specific cases like yours where the ball’s number occupies only a portion of one segment.


See the texture of the nearest ball in the screen shot shown above?
I’ve known that it was wrong to use sphere map texgen in the case. But as sphere map texgen has no relation with the rotation and translation of the object that is being mapped, why the edge of the ball texture still distorts?(especially when the ball is near the border of the viewport) What’s the reason?

[This message has been edited by Dong Ke (edited 10-29-2001).]