Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In a minecraft-like game I'm making, I get white edges on my cubes:

enter image description here

It is much more noticeable in darker textures. The textures are being setup like this: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Any help?

share|improve this question
3  
Can you show some code on how you render each cube and how you place cubes? –  Jonathan O Dec 19 '12 at 2:03
1  
Does wrapping the textures do anything different? What does the texture look like/size that you're binding to? –  Rubber Mallet Dec 19 '12 at 2:34

1 Answer 1

up vote 16 down vote accepted

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.

  • 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.
  • 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.
  • 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 x=100 with (100*0.6) + 0.6, and the left edge of the tile at x=101 with (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 (index+1)*size.
  • 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.
share|improve this answer
    
Looks like gaps to me - no texture bleeding (unless it's quite some high res texture) considering the tiny and sharp bits. –  Mario Dec 19 '12 at 10:34
    
Thanks, insetting the texture coordinates by a bit seems to fix it. –  Luis Cruz Dec 19 '12 at 12:52
    
@Mario I assume this is with NEAREST magnification - note the sharp border on the interior of the tile. So for that perspective, it's an infinite resolution texture. –  Kevin Reid Dec 19 '12 at 17:44
    
You could also use a texture array to avoid switching costs. –  danijar Feb 17 '13 at 16:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.