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 ?