How can I apply a texture to a glutSolidSphere?


I am writing an OpenGL model of the “Solar System” and am having some problems mapping textures to my planets. I am using glutSolidSpheres for the planets, with textures that are actual photos of the planets’ surfaces.

My problem is that my texture does not rotate with my planets. Each planet has accurate rotational and orbital parameters, so I want to be able to see the rotation. Instead, the texture is “floating” around the planet, and appears the same to the eye no matter where the planet is in its rotation/orbit.

I’m using environment mapping; is that the problem? Whenever I try to generate texture coordinates using another method, I can’t get the texture to stop tiling (I AM using mipmaps).

Any assistance would be greatly appreciated!

the only glut object that generates the texture coordinates 4 u is the teapot. for a sphere (and practically everything else) youre best to precalculate the texture coordinates yourself. theres 2 main ways u can build a sphere a geosphere (where each triangle is broken into 4 smaller triangles until the required sphere smoothness is meet) this tends to give better texture mapping accuracy. the other method is what glut uses where u have a number of latitude + logitude quads/tris.

Huh. So the texture gen isn’t actually getting passed any coordinates with a glutSolidSphere? Didn’t know that.

Do you think using a quadric with gluSphere would work? I have heard of that method, it would just make my (predominantly OO) code more complicated, so I hadn’t tried it yet.

Thanks muchly!

Texture gen works fine with a glutSolidSphere. What zed is saying is that glutSolidSphere doesn’t give you explicit texture coordinates. The reason your texture doesn’t rotate with the planet using enviroment mapping is because spherical environment mapping gets calculated based on the view angle and for a sphere, that just isn’t going to give you the result you want.

I wrote a little solar system app myself and how I did it was to use glu quadrics. Worked fine with that.

You could either stick with your current method and call glRotate to rotate the texture matrix OR do as suggested here and use glu Quadrics instead I did something similar to this while at uni - not OO though (pretty dodgy code now I look back - ugh)