PDA

View Full Version : GL_SPHERE_MAP problems



endash
09-02-2004, 08:49 PM
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?

Bob
09-03-2004, 12:09 AM
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 (http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_PG/sgi_html/ch10.html#id11059) .

09-03-2004, 01:15 AM
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

Bob
09-03-2004, 01:23 AM
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:

09-03-2004, 02:57 AM
hey Bob, could have happened to anybody :) 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.

endash
09-09-2004, 11:37 PM
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?

endash
09-21-2004, 01:36 PM
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.