Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: How can I apply a texture to a glutSolidSphere?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2001
    Location
    Winston-Salem, NC, USA
    Posts
    13

    How can I apply a texture to a glutSolidSphere?

    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!

  2. #2
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: How can I apply a texture to a glutSolidSphere?

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2001
    Location
    Winston-Salem, NC, USA
    Posts
    13

    Re: How can I apply a texture to a glutSolidSphere?

    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!

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: How can I apply a texture to a glutSolidSphere?

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Junior Member Regular Contributor
    Join Date
    May 2000
    Location
    Manchester - UK
    Posts
    138

    Re: How can I apply a texture to a glutSolidSphere?

    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)
    http://home.clara.net/paulyg/prog4.htm
    Paul Groves
    [b] pauls opengl page

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •