I’m having trouble trying to get texture arrays to work in my scene. I’ve found a few examples, like this, but they’re all using later versions, so I haven’t been able to learn much from them.
My code is based off this, except I’m using glTexImage3D in place of glTexStorage3D. It doesn’t give me any errors messages, but it just displays black.
To generate the textures:
int twidth, theight;
unsigned char* image1 = SOIL_load_image("awesomeface.png", &twidth, &theight, 0, SOIL_LOAD_RGB);
unsigned char* image2 = SOIL_load_image("container.jpg", &twidth, &theight, 0, SOIL_LOAD_RGB);
glGenTextures(1, &textures);
glBindTexture(GL_TEXTURE_2D_ARRAY, textures);
glTexImage3D(GL_TEXTURE_2D_ARRAY,
0, // level
GL_RGBA8, // Internal format
twidth, theight, 1, // width,height,depth
0,
GL_RGBA, // format
GL_UNSIGNED_BYTE, // type
0); // pointer to data
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, twidth, theight, 2, GL_RGBA, GL_UNSIGNED_BYTE, image1);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, twidth, theight, 2, GL_RGBA, GL_UNSIGNED_BYTE, image2);
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);
pass texture to shaders:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, textures);
glUniform1i(glGetUniformLocation(simulationObjectsShaderProgram, "textures"), 0);
and my fragment shader. Just hardcoding things for now. I’ll worry about getting the right texture coordinates when I can actually load the texture.
#version 330 core
in vec3 vertexColor;
in vec3 TexCoord;
out vec4 color;
uniform sampler2DArray textures;
void main()
{
//color = vec4(vertexColor, 1.0f);
color = texture(textures, vec3(.5, .5, 0.0));
}
any help is much appreciated!