Batch rendering textures

Hello! i tried batch rendering textures but this weird thing happens if i assign the 2nd texture to the face
image
so the textures are overlapping
here is the code:
vertex shader:
#version 460 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
layout (location = 2) in float aTexIndex;

uniform mat4 camMatrix;
out vec2 TexCoord;
out float TexIndex;

void main()
{
gl_Position = camMatrix * vec4(aPos.x, aPos.y, aPos.z, 1.0f);
TexCoord = aTexCoord;
TexIndex = aTexIndex;
}

fragment shader:

#version 460 core
layout (location = 0) out vec4 FragColor;

in vec2 TexCoord;
uniform sampler2D samplerT[2];
in float TexIndex;

void main()
{
int index = int(TexIndex);
FragColor = texture(samplerT[index], TexCoord);
}

Texture struct:
struct Texture {
GLuint textureID;

Texture(const char* FileName, GLint first, GLint second)
{
	glCreateTextures(GL_TEXTURE_2D, 1, &textureID);
	glBindTexture(GL_TEXTURE_2D, textureID); 
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	int width, height, nrChannels;
	unsigned char* data = stbi_load(FileName, &width, &height, &nrChannels, STBI_rgb);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
	stbi_image_free(data);
}

void BindTexture(GLuint unit)
{
	glBindTextureUnit(unit, textureID);
}

};

those functions are called in while loop
texture2.BindTexture(1);
texture.BindTexture(0);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.