glTeximage3D中的纹理格式

时间:2012-11-14 11:38:25

标签: opengl textures

我使用teximage3D和gl_texture_3D以及gl_texture_2D_array作为目标。

我正在创建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);               

1 个答案:

答案 0 :(得分:0)

我认为问题在于2d纹理数组使用整数作为纹理索引,而3d纹理则像S轴和T轴一样缩放R轴0-1。