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

Author Topic: Vertex Drawing Issue  (Read 3671 times)

0 Members and 2 Guests are viewing this topic.

Anthroyd

  • Guest
Vertex Drawing Issue
« on: April 07, 2018, 02:06:37 am »
Hi there,

My group's project uses a tilemap system to display graphics and interact with the game world. Unfortunately, every once in a while when the player moves on the tilemap, colored lines appear in between each tile and we're not sure why. The color of the lines matches the fuchsia color of the RenderWindow itself.

Any ideas on what could be causing this? We've tried actually overlapping the tiles so that instead of being drawn right next to each other (they're 16 x 16 in pixels), their edges are drawn in an overlapping fashion, such that every 15 or 14 pixels the next tile is drawn. We thought this might eliminate the issue if the issue happened to be some rounding error with where the tiles were being drawn, but unfortunately that little trick didn't change anything--we still get those pesky horizontal/vertical 1 pixel wide lines every so often.

More general information I'm throwing in: Our tiles are converted to vertices and stored in a vertex array for batch rendering.
« Last Edit: January 02, 2024, 01:24:15 am by Anthroyd »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Vertex Drawing Issue
« Reply #1 on: April 09, 2018, 06:42:48 pm »
It's a known issue due to OpenGL rasterization and you can find many threads about this.

When you move the view or tilemap to sub-pixel positions, OpenGL has to decide what pixel it should be to render your tile and it may just wrongfully pixel a texture position where you don't have anything or where the neighboring tile is connected to, so you end up with lines of nothing or lines of neighbor tiles.

Solutions to fix this, can be to only use integer positions, so you don't get into situations where OpenGL has to rasterize sub-pixels. Or you can first render your scene to a render texture and move that around. Or you could try and add pixels around your tiles, so when OpenGL picks neighboring pixels, it will still match properly (may still cause distortions).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Chaia*

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Vertex Drawing Issue
« Reply #2 on: April 10, 2018, 09:28:00 am »
You could also try to increase your tiles (in the texture file) by 1 Pixel around each edge of the tile (like a frame) and fill this 1 Pixel with the same information as the original "edge pixel" had. In your game you set your tex-coords still only on the original tile-coordinates (meaning w/o the "frame"). When OpenGL now samples outside your original tex-coords you do not get a color of the background or the neighboring tile but you basically "mimic" GL_REPEAT behaviour. Another solution would be to use ArrayTextures but thats not possible with SFML or you could use a single texture for each tiletype but this would be not very efficient.

Edit: just saw thats what eXpl0it3r was suggesting in the end. sorry for the double information
« Last Edit: April 10, 2018, 09:30:17 am by Chaia* »