0
我使用的是DDS立方體貼圖時遇到麻煩立方體貼圖,我只是得到一個黑色立方體這使我相信我有簡單的東西,這裏是到目前爲止的代碼:使用DDS壓縮圖像在OpenGL中進行多維數據集映射?
DDS_IMAGE_DATA *pDDSImageData = LoadDDSFile(filename);
//compressedTexture = -1;
if(pDDSImageData != NULL)
{
int height = pDDSImageData->height;
int width = pDDSImageData->width;
int numMipMaps = pDDSImageData->numMipMaps;
int blockSize;
GLenum cubefaces[6] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
};
if(pDDSImageData->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
blockSize = 8;
else
blockSize = 16;
glGenTextures(1, &textureId); int nSize;
int nOffset = 0;
glEnable(GL_TEXTURE_CUBE_MAP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_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);
for(int face = 0; face < 6; face++)
{
for(int i = 0; i < numMipMaps; i++)
{
if(width == 0) width = 1;
if(height == 0) height = 1;
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
nSize = ((width+3)>>2) * ((height+3)>>2) * blockSize;
glCompressedTexImage2D(cubefaces[face] ,
i,
pDDSImageData->format,
width,
height,
0,
nSize,
pDDSImageData->pixels + nOffset);
nOffset += nSize;
// Half the image size for the next mip-map level...
width = (width/2);
height = (height/2);
}
}
}
一旦這個代碼被稱爲我使用glBindTexture綁定紋理,並使用GL_QUADS和glTexCoord3f繪製一個立方體。
是否使用非DDS立方體貼圖,當它工作,或者你一般有這個問題?你在使用3D紋理座標嗎? – UncleZeiv 2010-05-25 11:36:33
我還沒有嘗試過用於非DDS,我很喜歡3D紋理座標。 – paj777 2010-05-26 14:42:27