upside down cubemap

hi folks,
i am making some experiments with cubemaps… can anyone tell me why my cubemap looks upside down??? ok i can flip textures, but i’d like a more “scientific” explanation.
Here is my code:

generation:

GLubyte data[2562563];
glEnable(GL_TEXTURE_CUBE_MAP_ARB);

glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,texture);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

for(int i=0;i<6;i++)
{
GENERATE THE PIXELS DATA

glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

if(i==4)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+5, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
if(i==5)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+4, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
else
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+i, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
// glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB+i,0,GL_RGB8,0,0,256,256,0);

}

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);

}
and here is the rendering:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glColor3f(1.0,1.0,1.0);

glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,texture);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

gluSphere(sphere, 3.0f, 64, 64);

glutSwapBuffers();
glutPostRedisplay();

nothing too exotic… I use GL_REFLECTION_MAP, cause if i try to set the texture generation to GL_SPHERE_MAP, it just craps all the textures… And that is anothere interesting topic… Why a spherical generated tex mapping won’t work on a simple sphere? In the afternoon i’ll try to build the same stuff with a “custom” sphere, and hand made normals… meanwhile…
thanks for any advice

As scientific as it gets, this is the spec wording.
The weirdness is explained by the table 3.20.
Try to figure out where your source texel is, by solving the equation for the new (s, t) backwards.

3.8.6 Cube Map Texture Selection

When cube map texturing is enabled, the ( s, t, r ) texture coordinates are treated
as a direction vector ( rx, ry, rz ) emanating from the center of a cube (the q
coordinate can be ignored, since it merely scales the vector without affecting the
direction.) At texture application time, the interpolated per-fragment direction vector
selects one of the cube map face’s two-dimensional images based on the largest
magnitude coordinate direction (the major axis direction). If two or more coordinates
have the identical magnitude, the implementation may define the rule to
disambiguate this situation. The rule must be deterministic and depend only on
( rx ry rz ). The target column in table 3.20 explains how the major axis direction
maps to the two-dimensional image of a particular cube map target.
Using the sc, tc, and ma determined by the major axis direction as specified in
table 3.20, an updated ( s, t ) is calculated as follows:

Major Axis Direction Target sc tc ma
+rx TEXTURE_CUBE_MAP_POSITIVE_X −rz −ry rx
−rx TEXTURE_CUBE_MAP_NEGATIVE_X rz −ry rx
+ry TEXTURE_CUBE_MAP_POSITIVE_Y rx rz ry
−ry TEXTURE_CUBE_MAP_NEGATIVE_Y rx −rz ry
+rz TEXTURE_CUBE_MAP_POSITIVE_Z rx −ry rz
−rz TEXTURE_CUBE_MAP_NEGATIVE_Z −rx −ry rz

Table 3.20: Selection of cube map images based on major axis direction of texture
coordinates.

s =1/2 * (sc/|ma| + 1)
t =1/2 * (tc/|ma| + 1)

This new ( s, t ) is used to find a texture value in the determined face’s twodimensional
texture image using the rules given in sections 3.8.7 through 3.8.9.

thx relic,
but at the end i solved my prob:
it seems like the automatic cenerated tex coord are wrong. i managed to build a custom sphere, with normal/tex map coordinates “hand” generated, and all worked well. Can’t imagine why the gl_gen couldnt do the same stuff…

Bye G.