Hello,
Referencing from here: http://www.opengl.org/wiki/Array_Texture, I've been trying to implement a texture array in my program. Unfortunately, I'm going wrong somewhere, but after a couple days of trying to figure out where, I'm a little stumped.
There is no error reported, and the objects themselves render fine (just without textures, so the world is a bunch of black/grey objects lit by the lighting, but minus any sort of textures).
A simplified version of the functions are roughly:
GLuint TextureArray;
glGenTextures(1, &TextureArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, TextureArray);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 500, 500, 2);//last three numbers are size of images and array
LoadTexture("prettypicture.png", 0);
LoadTexture("anotherprettypicture.png",1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
void Main::LoadTexture(const char* imageName, int layerNumber)
{
image.loadFromFile(imageName);//just a function to load image. Works fine when not in texture atlas
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layerNumber, image.getSize().x, image.getSize().y,1, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
}
Then, in the fragment shader (very paraphrased, don't take much too literally here):
in vec2 UV;
out vec4 color;
uniform2DArraySampler myTextureSampler;
int main(){
color = texture(myTextureSampler, vec3(UV, index));
}
and when drawing:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, TextureArray);
There's of course much more, though this is roughly what was changed from my working code. If I didn't include it here, it remains unchanged from my working examples (and so, likely the place I'm going wrong and causing the program to not rendering textures).
Either I'm missing a vital piece of information, or I'm doing something undoubtedly silly. The fact that no error is reported, leads me to think that the shader is probably fine, as are the draw commands, and I'm simply generating the texture array wrong.
Anyhow, any pointers or advice are more than welcome, and I appreciate any help
Cheers!