Results 1 to 3 of 3

Thread: Wants to use GL_TEXTURE_2D_ARRAY

  1. #1
    Newbie Newbie
    Join Date
    Jul 2016
    Posts
    2

    Post Wants to use GL_TEXTURE_2D_ARRAY

    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
    Code :
    //Тест загрузки нескольких текстур
    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
    Code :
    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";

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    did you check for any errors ?
    are all textures of the same size ?
    i think you need also some more glTexParameteri(...) to set: GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T

  3. #3
    Newbie Newbie
    Join Date
    Jul 2016
    Posts
    2
    Quote Originally Posted by john_connor View Post
    did you check for any errors ?
    are all textures of the same size ?
    i think you need also some more glTexParameteri(...) to set: GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T
    1) No, I did not check for errors. You want to me to use glGetError? Or for texture has its own command?
    2) Yes, both of have 400x400 texture size. The function LoadTexture() memorizes both sizes are for struct Textures_Mass[].
    3) Added. But there is no visible changes.

    I changed the code, it must be closer to getting result through GL_TEXTURE_2D_ARRAY.

    Program
    Code :
    //Тест загрузки нескольких текстур
    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 будуших текстур
     glTexStorage3D(GL_TEXTURE_2D_ARRAY,0, GL_RGB8, Textures_Mass[0].width, Textures_Mass[0].height, depth_texture_array); //создана "пустышка" неизменяемой текстуры
     
     //добавление 1-ой текстуры в текстурный массив, 0-вым слоем
     glTexSubImage3D(GL_TEXTURE_2D,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, 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);
     
     glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_LINEAR);
     
    }

    Shader
    Code :
    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;
    uniform sampler2DArray Textur_Array;
     
    layout (location = 0) out vec4 FragColor;
     
    void main()
    {
    	//FragColor = texture2D(Tex1, TexCoord.st);
        FragColor = texture(Textur_Array, TexCoord);
    }
     
    )END";

    At this point, one can see the contour the figure. But it has all color black.
    I think the problem must be somewhere in the loading textures for OpenGL.
    P.S. I can answer for a long time due to the fact I have the different time zone.

Similar Threads

  1. glBindImageTexture with GL_TEXTURE_2D_ARRAY
    By Iaolia456 in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-01-2017, 09:27 AM
  2. GL_TEXTURE_2D_ARRAY: how to resize images ?
    By john_connor in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-08-2016, 05:13 AM
  3. Compute shader and GL_TEXTURE_2D_ARRAY
    By __bob__ in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-16-2014, 05:35 AM
  4. GL_TEXTURE_2D_ARRAY help
    By JohnMcJohnson in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-17-2014, 05:29 PM
  5. glGenerateMipmap(GL_TEXTURE_2D_ARRAY)
    By vkMarco in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-25-2011, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean