PDA

View Full Version : How can I apply a texture to a glutSolidSphere?



daviem01
04-29-2001, 09:41 AM
Hey,

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!

zed
04-29-2001, 05:16 PM
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.

daviem01
04-29-2001, 06:56 PM
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!

Deiussum
04-30-2001, 09:27 AM
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.

Pauly
05-01-2001, 06:29 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif I did something similar to this while at uni - not OO though (pretty dodgy code now I look back - ugh)
http://home.clara.net/paulyg/prog4.htm