Environment Mapping, updating texture coordinates

I haven’t studied environment mapping in detail, my book discusses it briefly, and says that you need to generate new texture coordinates as the object moves, to move the reflections along with it. But my texures seem fixed in place, regardless of the orientation of the object.

I even tried adding an explicit transformation just to change the texture coordinates, but i get the same results regardless of what i use in place of ‘45’ in the code below.


Okay, I think I get what you’re trying to do. First, there is a difference between environment mapping and sphere mapping.

Environment mapping is a concept or process of generating a texture representing the world around your object. You then project that texture onto an object.

Texture projection is part of OpenGL environment mapping but is simply projecting some type of texture (a cube texture, a 2D texture, etc.) onto an object usually using automatic texture coordinate generation.

I mention this because you mention environment mapping, but it looks like you’re really just projecting a texture. Is that correct?

Asssuming so, you were expecting the GL_MODELVIEW matrix to change your texture coordinate generation. As you can tell, it’s unaffected as it should be. Say I have a cube map of a marble texture and I want to automatically map it to a vase. Should the textures stay contant on my screen as I move around the object? No, it should be camera independent.

Are your textures swimming (translating your object across the screen)? When you rotate the object, does the texture move with the object or stay relative to the camera? etc.

Yes I believe all this does is project a texture (a fish-eye photograph) onto an object.

the object appears as a shiny object moving about in a stationary room. I see different relections based on the orientation of the object, but not based on the viewpoint. I want the reflections to change according to the viewpoint, as they should.

Use Cube maps. Sphere mapping is view dependent by design. If you do use cube mapping, you must use a texture matrix identical to the rotation part of your view transform (Assuming that the cube map was generated at the origin of the world).

Note: Texture is not changed because the glTexGen creates texture coordinates after the draw call (glDraw*, glBegin/End), so it takes your modelview matrix at that point, not when you call glTexGen.