GL_SPHERE_MAP problems

I think I must be doing something wrong. I’m trying to use GL_SPHERE_MAP but keep getting what I think are odd results.

To see what’s going on, I’m using this simple rainbow texture:
http://www.cs.hmc.edu/~ben/pix/opengl_examples/rainbow-texture.png

And mapping it onto a sphere, I get this:
http://www.cs.hmc.edu/~ben/pix/opengl_examples/rainbow-shot.png

My sense is that sphere-mapping a sphere is essentially an identity function – that I should see the texture itself.

I’m pretty sure I’m doing things right:

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

  glEnable(GL_TEXTURE_GEN_S);
  glEnable(GL_TEXTURE_GEN_T);
 

I’ve tried using GL_NORMALIZE and not, and using GL_AUTO_NORMALIZE and not. I’ve played with the teapot and various other GLUT objects.

Am I mistaken? Does this look right, or is something wrong?

Sphere mapping is used to get a cheap reflection effect, and the texture you use should be an image of the surrounding environment as seen from the reflecting object. Was that what you wanted? Here’s a link on environment mapping .

Bob, great link, buts its broken (extraneous href). heres a quick fix of it:
http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/ch10.html

Endash, that looks good to me, buts its always a little hard to tell with sphere maps. heres a great little derivation of the texture coords you might find interesting:
http://www.cs.unc.edu/~hoff/techrep/spheremap.html

Thanks for noticing the broken link. I made the usual HTML-link (<a href=… ), and forgot to remove href= when I remembered the board had it’s own tags. Link fixed now. :cool:

hey Bob, could have happened to anybody :slight_smile: by the way, your link made it into my library. sgi’s got some kick-ass docs. i like that version much better than the one i had.

topic:
you know, whenever i debug cube maps, i always use a texture with text in it, like a letter in the middle of each face. that way i know exactly what it should like like, and how it should be oriented. much easier to see than gradients or lines. for a sphere map, maybe just a big “G” in the middle, some letter thats not symmetric in the x or y.

OK, I looked over the derrivations a bit, but I’m still getting odd results. As <bonehead> suggested, I was using a non-uniform texture so I could see what how the texture coordinates were being mapped, but if you look at the two screenshots, something seems wrong.

The topmost point on the sphere is gray, corresponding to (0.5, 0); it should be (0.5,1), right?

Similarly, the rightmost is black, corresponding to x = 0; shouldn’t it be (1, 0.5) there?

Am I wrong that sphere-mapping a sphere should draw the texture undistorted?

I figured it out. I had modified the texture example program from the red book. It uses glOrtho. My camera position was in the middle of that sphere, as far as the spehere mapping was concerned, even though geometrically I was outside of the sphere. glTranslate(0,0,theNearClipPlane) solved it.