2
\$\begingroup\$

I tried searching on the web but couldn't find a reason for this. When I render an object close to the camera, the object and texture renders fine. But further away from a fixed distance, it starts showing weird color lines on the texture.

Close to the camera, no lines:

Further away, color lines appear on texture:

enter image description here

My shaders are pretty simple.

#version 330 core

layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 tex;

uniform mat4 projMatrix;
uniform mat4 viewMatrix;

out vec2 uvCoord;

void main()
{
    gl_Position = projMatrix * viewMatrix * vec4(pos.xyz, 1.0f);
    uvCoord = tex;
}

#version 330 core

out vec4 FragColor;

uniform sampler2D texture1;

in vec2 uvCoord;

void main()
{
    FragColor = texture(texture1, uvCoord);
}

My texture parameters are:

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);

Any help would be appreciated!

Edit: I have generated mipmaps using glGenerateMipmap(GL_TEXTURE_2D)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Try turning mipmapping on \$\endgroup\$
    – Bálint
    Jun 25, 2019 at 4:24
  • \$\begingroup\$ @Bálint I have. glGenerateMipmap(GL_TEXTURE_2D); \$\endgroup\$
    – Rish
    Jun 25, 2019 at 5:35
  • 2
    \$\begingroup\$ You aren't using them. Put "GL_LINEAR_MIPMAP_LINEAR" as the min filter \$\endgroup\$
    – Bálint
    Jun 25, 2019 at 6:40
  • \$\begingroup\$ @Bálint, that looks like an answer to me. ;) \$\endgroup\$
    – DMGregory
    Jun 25, 2019 at 11:02

1 Answer 1

1
\$\begingroup\$

You forgot to actually use the generated mip maps. You need to pass GL_LINEAR_MIPMAP_LINEAR (or any of the 3 alternatives) as the third argument when setting the min filter.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .