Using texture array?

I’m trying to use texture array, but it’s only rendering black.

Here’s what I’m using:


std::vector<std::string> paths;
	paths.push_back("./resources/textures/brickwall.jpg");
	paths.push_back("./resources/textures/bricks2.jpg");
	this->texture = loadTextureArray(paths);

...
glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D_ARRAY, this->texture);
glUniform1i(glGetUniformLocation(shader.Program, "texture_diffuse1"), 0);

...

GLuint VWindow::loadTextureArray(std::vector<std::string> paths)
{
	// Generate texture ID and load texture data 
	GLuint textureID;
	glGenTextures(1, &textureID);
	int width, height;
	unsigned char* image = SOIL_load_image(paths[0].c_str(), &width, &height, 0, SOIL_LOAD_RGB);
	// Assign texture to ID
	glBindTexture(GL_TEXTURE_2D_ARRAY, textureID);
	glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGB, width, height, paths.size());

	glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, width, height, paths.size(), GL_RGB, GL_UNSIGNED_BYTE, image);
	SOIL_free_image_data(image);
	for (GLuint i = 1; i < paths.size(); i++)
	{
		image = SOIL_load_image(paths[i].c_str(), &width, &height, 0, SOIL_LOAD_RGB);
		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, width, height, paths.size(), GL_RGB, GL_UNSIGNED_BYTE, image);
		SOIL_free_image_data(image);
	}

	// Parameters
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
	
	return textureID;
}


And my shader:

uniform sampler2DArray texture_diffuse1;

...

= texture(texture_diffuse1, vec3(texCoords, 0)).rgb;

did you check for any gl errors anywhere ?
https://www.khronos.org/opengl/wiki/OpenGL_Error

glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGB, width, height, paths.size());

try using a “sized internal format”, like GL_RGB8
https://www.opengl.org/sdk/docs/man/html/glTexStorage3D.xhtml

here is an example:
https://sites.google.com/site/john87connor/texture-object/tutorial-09-6-array-texture

you have to make sure that all layers have the same resolution, if your image is smaller, make sure you dont access the image’s data array “out of range”

If you’re only updating a single depth slice, the depth parameter should be one.