Whiteclaws
Whiteclaws

Reputation: 942

OpenGL texture minification artifacts

I have this mesh that basically samples its textures from an atlas. It works as intended when the texture is magnified. enter image description here

However, whenever I look at it from a distance, I start seeing lines and blue-ish tints on textures as if they're glistening... enter image description here

This is the code used to specify image properties:

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

And I'm essentially loading a texture atlas with a configuration file as follows: enter image description here

count 5
name grass_top
uv 0.750 0.750 0.81250 0.81250
name grass_side
uv 0.18750 0 0.250 0.06250
name grass_bottom
uv 0.1250 0 0.18750 0.06250
name dirt
uv 0.1250 0 0.18750 0.06250
name stone
uv 0.0625 0 0.125 0.0625A

What could be the problem here, I am absolutely stumped...

Edit: after implementing Rabbid76's solution, this is how it looks! enter image description here

Upvotes: 2

Views: 576

Answers (1)

Rabbid76
Rabbid76

Reputation: 210918

I recommend limiting the mipmap layer to 4 as the size of a tile is 16x16. See Mipmap range and glTexParameter:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);

If you do not specify the maximum mipmap level, all mipmap levels up to a texture size of 1x1 are used for texture sampling. Above level 4 the tiles of the texture atlas get mixed.

Upvotes: 5

Related Questions