Hello, I’m directly sorry for my bad english, not found answers in my mother tongue how to properly use GL_TEXTURE_2D_ARRAY.
Most recently I managed to impose a first texture using GL_TEXTURE_2D. But to my surprise it was imposed absolutely on all polygons.
Now I understand why did it happen.
Studying GL_TEXTURE_2D_ARRAY I find it very convenient to use.
I want to download it a certain number of textures and then, using the texture coordinates select what kind of texture should be imposed on the polygon.
I have code which must doing it. However, due to of my inability this does not happen.
Please explain what I’m doing wrong.
Program
//Тест загрузки нескольких текстур
void LoadTexture_in_OpenGL() {
wchar_t FileName1[] = L"textures/Test1.jpg";
wchar_t FileName2[] = L"textures/test2.jpg";
LoadTexture(FileName1, &Textures_Mass[0]);
LoadTexture(FileName2, &Textures_Mass[1]);
glGenTextures(1, &TextureID); //создаем ID описатель текстуры.. лиш для одной текстуры (это будет 2D Array)
glBindTexture(GL_TEXTURE_2D_ARRAY, TextureID); //Говорим использовать этот описатель текстуры
GLuint depth_texture_array = 20; //Задаем количество слоев в нашей текстуре.. под 20 будуших текстур
glTexImage3D(GL_TEXTURE_2D_ARRAY,0, GL_RGB8, Textures_Mass[0].width, Textures_Mass[0].height, depth_texture_array, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); //создана "пустышка" неизменяемой текстуры
//добавление 1-ой текстуры в текстурный массив, 0-вым слоем
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,0, 0, 0, 0, Textures_Mass[0].width, Textures_Mass[0].height, 0, GL_RGB, GL_UNSIGNED_BYTE, Textures_Mass[0].imageData);
//добавление 2-ой текстуры в текстурный массив, 1-вым слоем
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, Textures_Mass[1].width, Textures_Mass[1].height, 1, GL_RGB, GL_UNSIGNED_BYTE, Textures_Mass[1].imageData);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
Shader
const GLchar* VertShaderCode_VeryLow = R"END(
#version 430
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexColor;
layout (location = 2) in vec3 VertexTexCoord;
layout (location = 3) in int VertexTexID;
out vec3 Color;
out vec3 TexCoord;
out int TexID;
uniform mat4 MVPMatrix;
void main()
{
TexCoord = VertexTexCoord;
TexID = VertexTexID;
Color = VertexColor;
gl_Position = MVPMatrix * vec4(VertexPosition, 1.0);
gl_PointSize = 40; //Не проверенно
}
)END";
//Frag Shader Very Low
const GLchar* FragShaderCode_VeryLow = R"END(
#version 430
in vec3 TexCoord;
in vec3 Color;
in int TexID;
uniform sampler2D Tex1;
layout (location = 0) out vec4 FragColor;
void main()
{
//FragColor = texture2D(Tex1, TexCoord.st);
FragColor = texture(Tex1, TexCoord.st, 1.0);
}
)END";