There are two possible causes for this type of problem, depending on exactly which problem it is. I'll list both:
1. You are seeing other colors from your texture along the edges of the tiles.
This looks to me like the problem in this case, because all of the edge pixels are one of three colors which are plausibly in your texture: white, black, and brown.
If you are using multiple tile images right next to each other in a single texture (a texture atlas), as I assume you are doing, this is inevitable. It occurs because the GPU does not perfectly match up interpolation along the edge of a triangle with interpolation along the texture, and you get little bits of the adjacent texture.
There are a number of things you can do.
- Use an array texture instead of a texture atlas. An array texture is made up of a stack of 2D images of the same size, and you specify a third coordinate to select one; it is intended exactly as a replacement for texture atlases without the filtering problem. However, array textures are a newer feature may not be available in the version of OpenGL you are using.
- Generate a 1-pixel border in each of your texture tiles, which replicates the color of the adjacent regular pixel. (This is essentially reimplementing GL's
CLAMP[_TO_EDGE], but in a way which is aware of texture atlases — your use thereof has no effect because most of your tile edges are not at the edge of the texture.) This is the solution I use in my own entry in the genre, Cubes. I know of no particular disadvantages except that it uses more texture memory.
- Very slightly inset your texture coordinates, so that they do not go all the way to the edge of the texture tile. Doing this too much will lead to a noticeable thinness of the edges of the texture compared to pixels in the middle.
- Use a single texture per tile type. This imposes texture-switching costs.
2. You are seeing through gaps between tiles.
I don't think this is the problem in this case, since there is no green ground seen through the gaps, but I'm including it for completeness.
This can occur when you are not providing exactly the same coordinates for the vertices of the meeting edges of adjacent tiles, which usually arises due to floating-point error. For example, if you have tiles of size 0.6 and compute the right edge of the tile at
(100*0.6) + 0.6, and the left edge of the tile at
(100*0.6), you will not get the exact same answer, and the difference can be visible as little specks of gaps.
The solution is to ensure that your arithmetic is consistent; some ways to do this are:
- Make sure you are not (even indirectly) computing
index*size + size, but only
- Make sure that your arithmetic is exact; the easiest way to do this is to make your tile size exactly 1.0, which will result in exact integer arithmetic even if you do your calculations with 32-bit floats (up to 16 million blocks from the origin, anyway).
- Use actual integers for vertex coordinate calculations; this gets you even more range.