Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Tilemap rendering gap lines  (Read 1279 times)

0 Members and 1 Guest are viewing this topic.

Brumus14

  • Newbie
  • *
  • Posts: 3
    • View Profile
Tilemap rendering gap lines
« on: October 07, 2023, 07:23:36 pm »
Hello,

I'm creating a tile based game in SFML with C++ and while I was rendering the map of tiles with the camera moving I get a bug where sometimes while moving the camera there are lines that appear between some of the tiles then they disappear for a while.

This was not happening until I tried to set the position of the mapSprite to the cameras position so I could create the mapTexture to the size of the camera instead of the size of the map in case it is big.

I have attached a video of what I mean. Any help would be appreciated and if you have any way I could improve my code that would be great.

Here is my Map class code:

(click to show/hide)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11039
    • View Profile
    • development blog
    • Email
Re: Tilemap rendering gap lines
« Reply #1 on: October 10, 2023, 08:10:38 am »
The issue is called texture bleeding, as "cut out" (texture rect) on the texture takes in pixel information outside of the defined texture rect.
It's caused because OpenGL has to decide what to render pixels a non-integer positions, and thus it ends up taking surrounding pixels.

There are multiple "solutions" to the problem, with different success rates.

You can add additional pixels around each of your tile, so if there's any bleeding, it wouldn't take pixels from the next tile. This can still leave these line artifacts, but just with pixels that match the current tile better.

You can try and render the map only at integer positions, while considering the offset or zoom of the view. This is not always feasible, especially if you want certain smooth renderings.

One mitigation that can help with how OpenGL decides on the rasterization, is to render everything to a RenderTexture first and then render that contents to the window. That way OpenGL has to fully rasterize the texture information for the RT and you might end up with less bleeding.

Ideally, you might end up with a combination of the solutions above.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Brumus14

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Tilemap rendering gap lines
« Reply #2 on: October 11, 2023, 01:02:36 am »
Thanks seems to be fixed by using integers instead of floats in the vertex array.

 

anything