Tiled SDL 2D Tilemap Glitch

I have a simple openGL engine using SDL working. I'm not using any SDL_Image stuff, its all just openGL. I've made 2d tilemap levels with a .txt file before by reading in the characters and using a switch statement to assign them to various textures and using their position in the file to render them. This method works fine and produces no graphical glitches.

Then I made a .tmx map in Tiled and used TmxParser to read the file into my program, and I'm able to render the map properly to the screen, but when I move up and down these black lines start to appear between the tiles.

The map loads in fine at first, its only once I start moving the camera around that it happens, and its only when the camera moves up or down.

I made a video to show exactly what I'm seeing, I see a lot of these type of issues when searching google but nothing that matches whats happening to me.


I'm not even sure if this is a problem with the code or what it could be so I don't know of any code to include.

This problem also happened to me when I was using Unity and importing a Tiled map with Tiled2Unity. In unity there were long horizontal line glitches on the tilemap, and now its happening to me again in c++, is this something to do with Tiled?

Has anyone encountered this before or know a solution?

Any help would be greatly appreciated, I feel stuck on this issue.
Are you using bilinear filtering? If you have a texture atlas and you draw your tiles by texture-mapping polygons into this atlas with bilinear filtering enabled, contiguous subtextures in your atlas can bleed into each other.
Here's an example. I've turned the contrast up to make it easier to see:
These artifacts don't show in places where I didn't make the text larger.

A simple solution is to add a 1 pixel border around each subtexture that repeats its neighboring color.
For example, a tile
would become
You probably have to give up power-of-two textures to implement this, though.

PS: Note that you don't need to edit your assets to do this. You can do it when you load them to memory, before you copy them to video memory.
Last edited on
I found the answer on GameDev's forums. The problem here was floating point precision. My camera was set to a position with ints, when the camera moves it uses the player position which is held in a vector of floats. I had to std::floor() the x and y position of the camera right before a translate to a new position and it fixed everything.

glm::vec3 translate(std::floor(-_position.x + _screenWidth/2), std::floor(-_position.y + _screenHeight/2), 0.0f);
_cameraMatrix = glm::translate(_orthoMatrix, translate);

without flooring the x and y, it was setting the position to a float and not a perfectly rounded int and that was causing the black lines between tiles and the flickering between tiles.

Here is the end result:
Last edited on
Topic archived. No new replies allowed.