我使用teximage3D,將gl_texture_3D和gl_texture_2D_array作爲目標。glTeximage3D中的紋理格式
我正在創建4層顏色並將其應用於球體上。所以我期待它會同樣在球體上應用4層。
但對於GL_TEXTURE_3D,它會重複所有層2次。而對於gl_texture_2D_array,它僅按照預期應用這些圖層一次。
int w = 4, h = 4, d = 4;
size_t size = w * h * d;
*format=GL_RGBA;
GLubyte *dataRGBA=new GLubyte[4*size];
for (int i=0; i<size/4; i++)
{
dataRGBA[4*i]=200;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=0;
dataRGBA[4*i+3]=255;
}
for (int i=size/4; i<size/2; i++)
{
dataRGBA[4*i]=0;
dataRGBA[4*i+1]=255;
dataRGBA[4*i+2]=0;
dataRGBA[4*i+3]=255;
}
for (int i=size/2; i<(3*size)/4; i++)
{
dataRGBA[4*i]=0;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;
}
for (int i=(3*size)/4; i<size; i++)
{
dataRGBA[4*i]=255;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;
}
glGenTextures(1,&id);
glBindTexture(*target11, id);
glTexParameteri(*target11, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// when this texture needs to be magnified to fit on a big polygon, use linear interpolation of the texels to determine the color
glTexParameteri(*target11, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// we want the texture to repeat over the S axis, so if we specify coordinates out of range we still get textured.
glTexParameteri(*target11, GL_TEXTURE_WRAP_S, GL_REPEAT);
// same as above for T axis
glTexParameteri(*target11, GL_TEXTURE_WRAP_T, GL_REPEAT);
// same as above for R axis
glTexParameteri(*target11, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexImage3D(*target11, 0, *format, w, h, d, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataRGBA);
請提供更多信息,例如您使用的實際紋理座標。此外,除了用於上傳圖像數據的功能外,二維陣列紋理和三維紋理與彼此無關。如果你試圖找出使用哪一個,那麼你不明白他們做得很好。 –
@Nicol:謝謝你的回覆。 我正在使用GL_TEXTURE_3D的標準化紋理座標。 對於2D_ARRAY,我將s,t歸一化,並將r作爲0到無層。 其實我正在加載一個球體的obj文件。你能告訴我怎樣與你分享obj文件,以便你能指出我錯在哪裏。 – debonair