i use batching method for this but somehow the textures are glitching to others’ textures. I have no depth test enable. I don’t know why this happen. Anyone has any idea to fix it?
You can see that the second texture is on the first (black) texture and it’s only happen when I use texture and not color to draw and sometimes they appear sometimes don’t.
my shaders:
#shader vertex
#version 330 core
uniform mat4 u_view;
uniform mat4 u_model;
uniform mat4 u_proj;
layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;
layout (location = 2) in float texID;
layout (location = 3) in vec2 texCoord;
out float v_texID;
out vec2 v_texCoord;
out vec4 v_color;
void main()
{
mat4 mat = u_proj*u_view*u_model;
gl_Position = mat*position;
v_color = color;
v_texID = texID;
v_texCoord = texCoord;
}
#shader fragment
uniform sampler2D u_textures[8];
in float v_texID;
in vec2 v_texCoord;
in vec4 v_color;
out vec4 FragColor;
void main()
{
vec4 color = v_color;
if (v_texID>=0.0) FragColor = texture2D(u_textures[int(v_texID)], v_texCoord)*color;
else FragColor = color;
}
my vertex datas :
Vertex2D v[] = {
0.f,0.f,0.f, 1.f,1.f,1.f,1.f, 0.f, 0.f,0.f,
100.f,0.f,0.f, 1.f,1.f,1.f,1.f, 0.f, 1.f,0.f,
0.f,100.f,0.f, 1.f,1.f,1.f,1.f, 0.f, 0.f,1.f,
100.f,100.f,0.f, 1.f,1.f,1.f,1.f, 0.f, 1.f,1.f,
150.f,0.f,0.f, 1.f,1.f,1.f,1.f, 1.f, 0.f,0.f,
250.f,0.f,0.f, 1.f,1.f,1.f,1.f, 1.f, 1.f,0.f,
150.f,100.f,0.f, 1.f,1.f,1.f,1.f, 1.f, 0.f,1.f,
250.f,100.f,0.f, 1.f,1.f,1.f,1.f, 1.f, 1.f,1.f
};
unsigned i[] = {0,1,2,1,2,3, 4,5,6,5,6,7};
texID is just for texture slot.
