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