1 year ago

#294772

test-img

Jaysmito Mukherjee

texture(sampler2DArrray, vec3(UV, layer)) only gives first texture for all layers

Code:

glGenTextures(1, &textureArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, textureArray);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);

glBindTexture(GL_TEXTURE_2D_ARRAY, textureArray);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGB8, 512, 512, textureNodes.size());

for(int i = 0; i < textureNodes.size(); i++)
{
    textureNodes[i]->texture->Resize(512, 512);
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, 512, 512, 1, GL_RGB, GL_UNSIGNED_BYTE, textureNodes[i]->GetData());
}

glBindTexture(GL_TEXTURE_2D_ARRAY, 0);

GLSL:

Try 1.

   FragColor = vec4(texture(_Textures, vec3(TexCoord, 0)).rgb, 1.0f);

Try 2.

   FragColor = vec4(texture(_Textures, vec3(TexCoord, 2)).rgb, 1.0f);

Try 3.

   FragColor = vec4(texture(_Textures, vec3(TexCoord, 0.5)).rgb, 1.0f);

All gives the first texture(0) although there are 4 textures loaded.

c++

opengl

glsl

textures

texture-mapping

0 Answers

Your Answer

Accepted video resources