View Full Version : Tile troubles

11-09-2011, 01:58 AM
Hello All.

I'm having some trouble with creating a 2D tiled world in OpenGL.

The image I want for the tiles is part of a large texture. For each tile, I use the right uv coords so the shader knows where to find the tile image in the texture.

It works fine most of the time. But when I start moving the camera around the scene, some lines appear between some of the tiles. This always affects a whole line or colomn of the tiles.

I'm now using a placeholder texture with diagonal lines so I can see exactly where the tiling isn't working. With a closer look, I can see that the lines are in fact part of the large texture. For example, with vertical lines the uv coords take an extra pixel to the left of the tile, but the right side is not affected because the diagonal lines of the tiles are not broken.

Here is a screen shot of what I'm talking about:


You can see I singled out a tile to show the whole tile image. You can also see that I cleared two tiles to the left of the red line to show that the line is part of the tile that is to the right. The pixels to the left of the tile in the large texture are red, and if I change their color in the texture, the line becomes that same color.
If I move the camera from the current position, the line will be gone. If I keep moving the camera lines will appear at different places. However, the lines do not appear randomly, if I restart the application and replace the camera in the same spot, the same line will appear.

My original thought was a round up error, but I thought the shader just used the UV coords that I give it. Why would it only do it for certain tiles on the screen if I give them all the same uv coords? I quite sure the transformation matrices don't affect them, do they ?

I'm running under windows 7 using home grown rendering engine based on SDL/OpenGL/GLSL.

I assume the problem is somewhere in my code, but I thought it was worth seeing if anyone else has had the same problem ? or if anyone has any ideas ?


11-10-2011, 02:22 AM
Hello again.

So, I think the problem is coming from the texture filtering. The camera is moved away from the scene, so the min filter is used. It is set to GL_NEAREST, I've tried the other settings. They do change the result, but the tiles are never perfect.

I think the only solution is to devide the large texture into multiple small ones, one texture per image. Does anyone have a better idea ?

11-10-2011, 04:08 AM
The problem lies with the fact the source texture is a texture atlas.
With any kind of filtering adjacent texels will be sampled and applied to the scene - and you don't want this to happen.
The solution is to ensure there are black borders around the elements in the texture atlas of around 2-3 pixels. That should stop the filtering bleeding through some of the adjacent tiles.
Or, as you say, supply independant textures.