Cubemap face orientation: how to

Hello everyone,

I am trying to get cubemaps working in my program and I can't seem to find a logic for how I am supposed to upload the texture.

This is the texture I am uploading:

[ATTACH=CONFIG]1140[/ATTACH]

and this is the code I am using:


const uint imageSize = width_ * height_ * bpp_ ;

for( uint i = 0; i < 6; ++i )
{
	glTexImage2D(
		GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
		internalFormat_,
		width_, height_, 0,
		pixelDataFormat_, GL_UNSIGNED_BYTE,
		imagePtr + ( imageSize * i )
		);
}

Before you ask, yes, I already made sure the texture is read correctly (if I import the texture as a 2d texture, it looks like the one I put above).
To render this, I am using a super simple shader that samples the cubemap with the world space normal.


OUT_FragmentColor = texture( colorTexture, normalize( worldSpaceNormal ));

The case I am using is a sphere centered at the center of the axis. I am using right hand coordinate everywhere in my program.
This is what I get when I render the sphere and I sample the cubemap (approximate camera positions):

from 1,1,1 looking down to -1,-1,-1
[ATTACH=CONFIG]1141[/ATTACH]

from -1,-1,-1 looking up to 1,1,1
[ATTACH=CONFIG]1142[/ATTACH]

from 0,0,1 looking down to 0,0,-1
[ATTACH=CONFIG]1143[/ATTACH]

As you can see the faces are correct: RED is pointing toward positive X, GREEN is pointing toward positive Y and BLUE is pointing toward positive Z.
For some reason though the orientation of the faces is not correct.
Now I could just “make it work”, but I would like to understand the logic of what the opengl call expects from the data.

As much as I looked around, I couldn’t find any thorough description of how the faces should be organized.

Thanks in advance for your reply,

Paolo

I found something very interesting: this is a gpu capture of a cubemap used in the cubemap opengl example from the OpenGL superbible 6:

[ATTACH=CONFIG]1144[/ATTACH]

As you can see, even in the profiler the cubemap is “upside down” with respect as you are normally used to see it.

For clarity, these are the faces:

[ATTACH=CONFIG]1145[/ATTACH]

Section 8.13 of the OpenGL 4.5 specification has Table 8.19:


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

The sc and tc columns give the cube-space axes corresponding to the s and t axes within the face.

Here’s a picture of how the images look.

Thanks Alfonse and GClements. I missed that part in the spec … :frowning:
Thank you.