SFML community forums

Help => Graphics => Topic started by: Eika on November 07, 2016, 02:18:47 pm

Title: Getting half a pixel from the scaled sprite?
Post by: Eika on November 07, 2016, 02:18:47 pm
Hello,

Im using SFML.Net 2.2

Making a raycasting game, where i need to get vertical strips from the texture.
I use scaling to make the sprite to have desired height

A sprite that is far away, will need to take use from texture per pixel drawn, so it will be scaled a lot more. I use this to find out how many pixels i need to get:
var widthGet = (int)Math.Round(1/scale);
So if scale is 0.5 (object is far enough that the image size is scaled by 0.5), i would get 2 pixels from the scaled texture(1 pixel in screen).

But, now i have issue when the scaling is bigger than or equal to 2, i would scale the texture say by 2, then calculate that i need to get half a pixel from the scaled texture, and get nothing drawn.
I tried doing a simple check such as:
if(widthGet == 0) widthGet = 1;
But, now these strips show double the amount needed(it looks fine, because they get drawn over the next strip)
However, the last strip from the close object is not getting drawn over, which is a problem.

Is there a way to scale the texture 2x, and then get what would be an equivalent of a half pixel from the original?

http://pastebin.com/eCU690jm (http://pastebin.com/eCU690jm) relevant code