Output cubemap texture object as bitmap images

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);

}

It seems that this problem is a driver bug and finally i found some work around :biggrin-new::biggrin-new::biggrin-new: :


void TextureGL::SaveCubeMapToImage()	// this save all 6 faces of cube map into images in harddrive
{

	BYTE front[3 * 128 * 128];
	BYTE back[3 * 128 * 128];

	BYTE top[3 * 128 * 128];
	BYTE bottom[3 * 128 * 128];

	BYTE left[3 * 128 * 128];
	BYTE right[3 * 128 * 128];

	GLuint CarrierText;
	GLuint CarrierFBo;

	glGenTextures(1,&CarrierText);
	glBindTexture(GL_TEXTURE_CUBE_MAP, CarrierText);

	glGenFramebuffers(1,&CarrierFBo);
    glBindFramebuffer(GL_FRAMEBUFFER,CarrierFBo);


	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, this->_mTexture, 0);
	glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGB,0,0,128,128,0);
	glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,right);



	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, this->_mTexture, 0);
	glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGB,0,0,128,128,0);
	glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_BGR,GL_UNSIGNED_BYTE,left);



	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, this->_mTexture, 0);
	glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGB,0,0,128,128,0);
	glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_BGR,GL_UNSIGNED_BYTE,top);


	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, this->_mTexture, 0);
	glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGB,0,0,128,128,0);
	glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_BGR,GL_UNSIGNED_BYTE,bottom);



	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, this->_mTexture, 0);
	glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGB,0,0,128,128,0);
	glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_BGR,GL_UNSIGNED_BYTE,front);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, this->_mTexture, 0);
	glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGB,0,0,128,128,0);
	glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_BGR,GL_UNSIGNED_BYTE,back);

	glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glDeleteFramebuffers(1,&CarrierFBo);
	glDeleteTextures(1,&CarrierText);


	  GLenum err;
	    while ((err = glGetError()) != GL_NO_ERROR) {
	        std::cerr << "OpenGL error: " << gluErrorString(err) << std::endl;
	    }
	// write this images down
	FIBITMAP* r = FreeImage_ConvertFromRawBits(right, 128, 128, 3*128, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FIF_BMP, r, "resources/textures/Irradiance/posX.bmp", 0);


	FIBITMAP* l = FreeImage_ConvertFromRawBits(left, 128, 128, 3*128, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FIF_BMP, l, "resources/textures/Irradiance/negX.bmp", 0);


	FIBITMAP* t = FreeImage_ConvertFromRawBits(top, 128, 128, 3*128, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FIF_BMP, t, "resources/textures/Irradiance/posY.bmp", 0);


	FIBITMAP* b = FreeImage_ConvertFromRawBits(bottom, 128, 128, 3*128, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FIF_BMP, b, "resources/textures/Irradiance/negY.bmp", 0);


	FIBITMAP* f = FreeImage_ConvertFromRawBits(front, 128, 128, 3*128, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FIF_BMP, f, "resources/textures/Irradiance/posZ.bmp", 0);

	FIBITMAP* bac = FreeImage_ConvertFromRawBits(back, 128, 128, 3*128, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FIF_BMP, bac, "resources/textures/Irradiance/negZ.bmp", 0);

}

I´am curious. What GPU/driver/os are you using?

Ubuntu 14.04 LTS, Nvidia Geforce 760 GTX (MSI version) diriver the latest one 375 i guess