Cracks between tiles [SOLVED]
Hey everyone. I'm having a small issue with tiling.
The problem is that after a while with the player moving, small "cracks" appear between the tiles of the map. I believe that the issue is caused by using floats and accumulating errors for the positions of everything right?
Is there some way to eliminate this other then using ints for positions?
[Edited by - davek20 on January 5, 2009 7:57:52 PM]
Are the cracks in between the tiles, or the textures? If the latter, you probably have an incorrect wrapping/filtering mode on your texture. If the former, integer coordinates are one possible solution (but they will be transformed into floats anyway by the graphics card, which only operates on floats), and another is to make the tiles share their corner vertices, which will also reduce your vertex count significantly (you might have to get clever with the texture coordinates, and you will certainly need to use a texture atlas, which you should be already).
Assuming you're dealing with 2d tiles with floats for positions, have you tried snapping/converting the position to ints before rendering? You can still keep your actual gameplay code using floats, just draw it at the nearest int position.
The cracks are between the actual tiles.
Here are some screen shots: The first one is fine, but when I move slightly I get the cracks (I've also noticed that the cracks are always vertical)
Right now, each tile has 4 vertices. As for the texture, it is one large texture with all the tiles on it. I'm using glDrawArrays() with the primitive as GL_QUADS and there are vertex, index and texture coordinate arrays.
swiftcoder, can you elaborate on how I might change the texture coordinates if I make the tiles share vertices?
EDIT:
OrangyTang, I just converted the drawing code to use ints, and the cracks have disappeared but it is really jerky when I move. So I don't think I will use that solution.
Here are some screen shots: The first one is fine, but when I move slightly I get the cracks (I've also noticed that the cracks are always vertical)
Right now, each tile has 4 vertices. As for the texture, it is one large texture with all the tiles on it. I'm using glDrawArrays() with the primitive as GL_QUADS and there are vertex, index and texture coordinate arrays.
swiftcoder, can you elaborate on how I might change the texture coordinates if I make the tiles share vertices?
EDIT:
OrangyTang, I just converted the drawing code to use ints, and the cracks have disappeared but it is really jerky when I move. So I don't think I will use that solution.
Quote:Original post by davek20
OrangyTang, I just converted the drawing code to use ints, and the cracks have disappeared but it is really jerky when I move. So I don't think I will use that solution.
It would help if we knew what kind of range the tiles are in. Usually you'd use pixel values so rounding to the nearest int shouldn't make scrolling jerky unless you're doing something wrong or you're using a different coordinate system/range. Depending on what you're doing it may also make sense to snap the camera coords to whole numbers rather than (or as well as) snapping the drawing coords. Posting relevent code snippets would be helpful too.
You mentioned that switching to integers made it jerky. Are you "using" integers or are you converting to integers at the last second? I use 64-bit integers to time my transformations in my OpenGL applications. I have the smoothest results by throwing all of my calculations in at once and only type-casting if I absolutely have to. Every time you divide or multiply by something with a limited number of decimal places you lose a little bit of accuracy. Do it 6 times and you lose a lot.
On that note, try __int64 and/or doubles :)
On that note, try __int64 and/or doubles :)
Actually, I believe that the problem is being caused by my camera. I casted the camera position to ints (not the actual drawing positions), and that caused the scrolling to be jerky.
I just tried something and it seemed to work well (although it is rather hackish). I just take the camera position and clamp it to the nearest 0.5 value and there are no more cracks in the tile. I guess that clamping to the nearest int was too much to clamp it to.
I just tried something and it seemed to work well (although it is rather hackish). I just take the camera position and clamp it to the nearest 0.5 value and there are no more cracks in the tile. I guess that clamping to the nearest int was too much to clamp it to.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement