Hello
i’m working on environment mapping. So i created a dynamic cube_map using geometry shader and gl_layer to single pass render all 6 direction thus this cube map texture is attached to an FBO. every thing worked fine. until i
decided to output this generated cube map as bmp images ( 6 faces --> 6 images). for this task i used glGetTexImage which take GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y…etc
the problem is that the only out put image i get is the one attached to GL_TEXTURE_CUBE_MAP_POSITIVE_X the rest is corrupted data not that the cube map is rendered correctly in the screen.
this is how i created my cube map and bound it to FBO
// 2-generate the color buffer for the cube map simple as we did in cubemapTexture function
glGenTextures(1,&this->_mTexture);
glBindTexture(GL_TEXTURE_CUBE_MAP, this->_mTexture);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// loop throw the 6 faces of the cube again
for(uint i = 0; i < 6; i++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,0,GL_RGB,w,h,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);
//3- generate the FBO
glGenFramebuffers(1,&this->_mFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER,this->_mFrameBuffer);
//4-attach CubeMap to FBO
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, this->_mTexture, 0);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, this->_mdepthTexture, 0);
than i do my rendering just fine
here this is the code to save my cube map into bmp file not that every face is size of 64 * 64 and the problem is only this call glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,right); that yeild a correct bmp image of a correct cube face the rest give garbage pixels. to summarise i’m trying to download the cubemap texture from GPU to CPu and it seems that only one face that get thro i looked every where could not find solution also i have installed lates Nvidia driver in case this is some kind of bug.
thank you for your attention best regard.
void TextureGL::SaveCubeMapToImage() // this save all 6 faces of cube map into images in harddrive
{
BYTE front[3 * 64 * 64];
BYTE back[3 * 64 * 64];
BYTE top[3 * 64 * 64];
BYTE bottom[3 * 64 * 64];
BYTE left[3 * 64 * 64];
BYTE right[3 * 64 * 64];
glBindTexture(GL_TEXTURE_CUBE_MAP, this->_mTexture);
// get textures from cube map
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,right);
glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,left);
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_BGR,GL_UNSIGNED_BYTE,top);
glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_BGR,GL_UNSIGNED_BYTE,bottom);
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_BGR,GL_UNSIGNED_BYTE,front);
glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_BGR,GL_UNSIGNED_BYTE,back);
// write this images down
FIBITMAP* r = FreeImage_ConvertFromRawBits(right, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, r, "resources/textures/Irradiance/posX.bmp", 0);
FIBITMAP* l = FreeImage_ConvertFromRawBits(left, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, l, "resources/textures/Irradiance/negX.bmp", 0);
FIBITMAP* t = FreeImage_ConvertFromRawBits(top, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, t, "resources/textures/Irradiance/posY.bmp", 0);
FIBITMAP* b = FreeImage_ConvertFromRawBits(bottom, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, b, "resources/textures/Irradiance/negY.bmp", 0);
FIBITMAP* f = FreeImage_ConvertFromRawBits(front, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, f, "resources/textures/Irradiance/posZ.bmp", 0);
FIBITMAP* bac = FreeImage_ConvertFromRawBits(back, 64, 64, 3*64, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, bac, "resources/textures/Irradiance/negZ.bmp", 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}