Normal array screws up cube mapping

If I don’t use a normal array, my cubemaps are mapped correctly. If I use a normal array, my cubemaps get totally screwed up. Their mapping gets changed by the surface normals, in a really bad way.

The reason I use a normal array is because I am rendering the cubemap along with several other textures in a single pass. Am I required to draw cubemaps in a separate pass?

Insufficient informations to say what’s wrong.
If you don’t fetch normals from a normal array all vertices will use the same normal from the current vertex state. Default for that is (0,0,1).
Sounds like you apply some texture coordinate generation based on the normal, like cube map reflection and are not prepared to handle that in the correct texture unit, the one with the cube map. Or your normal array is wrong.

When I just use (0,0,1) for all faces, cubemapping looks fine. When I use the face normals, the orientation of cubemap on the different faces does not line up at all. It would seem that normals influence the cubemapping algorithm, which is undesirable, since it obviously works fine when no normals are input at all. Therefore I need to either change a setting so that the cubemapping routine ignores the normals, or else I have to render the cubemap in a separate pass.

If there was a way to indicate separate normals for each texture unit, I would be fine, but I don’t believe there is.

Here are some images to demonstrate the problem.

If no normals are indicated, the cubemap looks fine:

When I use a normal array containing the face normals, the faces seem to each be flipped to show the opposite side of the cubemap they should be showing. Flipping the normals has no effect on this.

The fact that it works perfectly when no normals are indicated leads me to believe this isn’t a problem with my calculated normals.

Originally posted by halo:
If there was a way to indicate separate normals for each texture unit, I would be fine, but I don’t believe there is.
You misunderstood. I was talking about glTexGen reflection_map or normal_map and that is per texture unit.

The fact that it works perfectly when no normals are indicated leads me to believe this isn’t a problem with my calculated normals.
Well, you use your normals and the image is not what you expected.
Check your TexGen settings and normals.
For such cases it’s worth drawing the normals at all vertices of each face. With face normals there should be three orthogonal lines pointing outward (or inward, depending on what you intend to do) at each cube corner.
If you just want to map the cube, don’t use TexGen, specify the correct glTexCoord3f parameters.
Also check the face winding and read the spec about cube mapping.

Show some code and explain what effect you want to achieve.

I am using GL_REFLECTION_MAP. I expect it to appear as it does in the first image. Having a normal array changes the appearance, which makes no sense to me. It works perfectly without normals, so it’s no like there is some combination of normals I am trying to find to make it work. Here’s my code for setting up the cubemap:

glActiveTextureARB currenttextureunit
glClientActiveTextureARB currenttextureunit
gldisable GL_TEXTURE_2D
glEnable GL_TEXTURE_CUBE_MAP
glmatrixmode GL_TEXTURE
glpushmatrix()				
glloadmatrixf Float Ptr CURRENTCAMERA.CubeMapMatrix
glmatrixmode GL_MODELVIEW
glbindtexture GL_TEXTURE_CUBE_MAP,env_cubemap.gltexture
glEnable GL_TEXTURE_GEN_S
glEnable GL_TEXTURE_GEN_T
glEnable GL_TEXTURE_GEN_R
glTexGeni GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP
glTexGeni GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP
glTexGeni GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP
glTexEnvi GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE
glTexEnvi GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_INTERPOLATE
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOUS
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE2_RGB,basetextureunit
glTexEnvi GL_TEXTURE_ENV,GL_OPERAND0_RGB,GL_SRC_COLOR
glTexEnvi GL_TEXTURE_ENV,GL_OPERAND1_RGB,GL_SRC_COLOR
glTexEnvi GL_TEXTURE_ENV,GL_OPERAND2_RGB,GL_SRC_ALPHA
glTexEnvf GL_TEXTURE_ENV,GL_RGB_SCALE,1.0

I expect it to appear as it does in the first image.
I figured that, but what does it represent? A reflection on a shiny cube or a skybox?
The viewer will be outside or inside that box?
Should the reflection be viewer dependent or fixed?
These are the things which help to provide a solution.

Having a normal array changes the appearance, which makes no sense to me.
Read the OpenGL 2.0 spec at chapter 2.11.4 “Generating Texture Coordinates” which explains why normals make a difference and that reflection is used with sphere maps.

Then read chapter 3.8.6 Cube Map Texture Selection on how these coordinates are used to address texels in a cubemap.

If you have delved through that you just need to figure out which TexGen mode will result in the texture mapping application you want or if you need one at all.

I am using this for a reflection on a shiny surface.

The mapping should change with the camera position. I generate the cubemapmatrix by doing a transpose of the camera matrix.

Do I have to mess with the cubemap matrix some more to make it play right with the normals, or what?

But you’re not using any different transforms in the other picture are you?Are you SURE the only thing that changes between the two renderings is the Enable NORMAL_ARRAY?

How do you specify your normals in the correct rendering anyway?Is it done with immediate mode?