SFML community forums

Help => Graphics => Topic started by: TheMagicNumber on November 23, 2012, 04:12:16 am

Title: VertexArray Rendering Issues
Post by: TheMagicNumber on November 23, 2012, 04:12:16 am
I recently made a tile map renderer using VertexArrays and noticed that it does not work as expected with an odd window height. Here are some screenshots showing what is happening:

800x600 window: http://i.imgur.com/tcBhK.png
800x601 window: http://i.imgur.com/tYSQS.png

I am using one texture for all tiles so the white you see is from the row below it. I am using SFML.NET.

Code can be found here: https://github.com/Rohansi/Californium/blob/master/Californium/TileMap.cs

Anyone know how I can fix this?

Title: Re: VertexArray Rendering Issues
Post by: Laurent on November 23, 2012, 08:06:51 am
Decimal coordinates can produce this kind of artifact.
Title: Re: VertexArray Rendering Issues
Post by: TheMagicNumber on November 23, 2012, 09:45:14 am
Decimal coordinates can produce this kind of artifact.
No decimal coordinates are used (or are floats that inaccurate near zero). It is something in SFML causing inaccuracies in the rendering. Here (http://i.imgur.com/KKnOb.png) is another screenshot of a window that I maximized but did not alter the view for. To show that it is displaying part of another tile I added a black pixel to the tile directly below the grey one, shown here (http://i.imgur.com/ae5H9.png).

Using decimal coordinates for a view will create the same artifacts but I am rounding its position. The only code difference for the comparison in the first post is the initial RenderWindow size. I can specify any even height and it will look fine, but odd heights are an issue. It is also worth noting that all widths appear to work with no issues.
Title: Re: VertexArray Rendering Issues
Post by: TheMagicNumber on November 24, 2012, 04:21:42 am
I have found a workaround for this as I was trying to replicate the issue. Offsetting View.Center.Y by 0.5 if View.Size.Y is an odd number will fix it. Although I found this I am still unable to replicate the problem. Resizing the window is the closest I can get it. It still demonstrates strange behavior because resizing the window affects my texture coordinates.
Title: Re: VertexArray Rendering Issues
Post by: TheMagicNumber on November 26, 2012, 01:59:28 am
Just got around to trying zooming and I see it again. I'm not really sure of how to get this working correctly, I don't think my VertexArray generation is wrong.

Edit: Just tried offsetting texture coordinates by (0.01, -0.01) and it appears to work in all cases I know of. Strange.
Title: Re: VertexArray Rendering Issues
Post by: Laurent on November 26, 2012, 07:57:18 am
Quote
Just tried offsetting texture coordinates by (0.01, -0.01) and it appears to work in all cases I know of. Strange.
That's what you get when your name is TheMagicNumber ;D
Title: Re: VertexArray Rendering Issues
Post by: TheMagicNumber on April 18, 2013, 10:20:43 pm
I was working on this again and realized it affects Sprites too.

800x600: http://i.imgur.com/g4eUQ9d.png
800x601: http://i.imgur.com/UciHz6v.png

I can't use the same workaround for sprites because Sprite.TextureRect is an IntRect.
Title: Re: VertexArray Rendering Issues
Post by: eXpl0it3r on April 18, 2013, 11:13:22 pm
So is your view still set to integers and your sprites also set to integer?

Anyways it's a known problem, but I haven't seen a really clean fix. What I suggest though, is to change the texture and place a one or two pixel wide transparent line between all the images, so if for some strange reason it shows one pixel further than it should, it will get the transparent line and render nothing there. For not connected entities, this might work well.
But make sure you're not moving the view with decimals, but always round to integers!
Title: Re: VertexArray Rendering Issues
Post by: Nexus on April 19, 2013, 12:05:49 am
The problem has been known since a long time.
http://en.sfml-dev.org/forums/index.php?topic=5952.0

There are many other threads related to this issue, you can find them with the search function.
Title: Re: VertexArray Rendering Issues
Post by: TheMagicNumber on April 30, 2013, 04:32:27 am
So is there any chance of a fix or am I going to need to find something else?