SFML community forums

Help => Graphics => Topic started by: Clairvoire on November 03, 2009, 11:01:27 pm

Title: Sprite::Scale() throws off position
Post by: Clairvoire on November 03, 2009, 11:01:27 pm
With smoothing turned off, which I do for almost all my images since they're all sprites, scale() will offset the (x, y) coordinates of my sprite by "scalefactor * imagesize * ~0.4"

Luckily, I knew about the offset trick in Sprite's Render() function, "GLCheck(glTranslatef(0.375f, 0.375f, 0.f));".  Commenting this out solves my problem.  

I didn't see it mentioned anywhere, so I thought I'd give a heads up~
Title: Sprite::Scale() throws off position
Post by: Nexus on November 04, 2009, 12:11:57 am
What irony, as this line was added to fix a rendering bug. ;)
For more information, see http://www.sfml-dev.org/forum/viewtopic.php?t=1377

But what was your exact problem? Probably, there's a better solution which needs no intrusion into SFML. Or, maybe another modification in SFML code is required to fit a further case. :D
Title: Sprite::Scale() throws off position
Post by: Clairvoire on November 04, 2009, 01:17:34 am
Oh, I made a spritesheet to represent a lifebar.  It grows longer as the player levels up, so the sheet has a 1 pixel wide strip in it that would be drawn repeatedly, each time more 1 pixel to the right, to make it longer.

That is, until I noticed Scale()ing it did the same job with a little less code and a lot fewer rendering calls.

... Reading that thread you linked makes me kinda nervous though.  xD  
using floats for stuff that needs to be pixel perfect already has me a little paranoid.  I hope I'm not undoing some sort of really critical rendering fix by commenting out that, but I'm not sure how else to fix the scaling issue.

[Edit:] I forgot to mention, I use a viewport which zooms the screen in by a factor of 2.  There was an odd 1 pixel offset in the x and y I never understood, which I just noticed was now fixed because of commenting out that line.
Title: Sprite::Scale() throws off position
Post by: Laurent on November 04, 2009, 08:59:59 am
That's right, this line of code creates new issues with scaling. I think I should put it before other transformations, so that it doesn't impact them.

By the way, SFML 2 already uses a completely different fix for pixel perfect rendering.
Title: Sprite::Scale() throws off position
Post by: Nexus on November 04, 2009, 11:28:03 pm
Quote from: "Laurent"
By the way, SFML 2 already uses a completely different fix for pixel perfect rendering.
Okay. I haven't updated for a while, I'm still using the fix in the linked thread.

Laurent, is the newest revision more or less stable? I ask because you have recently done some experiments, and I don't know if there might still be severe problems in the SVN version. ;)
Title: Sprite::Scale() throws off position
Post by: Laurent on November 04, 2009, 11:40:42 pm
The only major issue with SFML 2 is, as far as I know, an error related to OpenGL contexts on Linux with some graphics cards. I made a fix recently but didn't get much feedback.
Title: Sprite::Scale() throws off position
Post by: Chebastian on October 13, 2011, 09:52:45 am
hows it going with this?
Title: Sprite::Scale() throws off position
Post by: Laurent on October 13, 2011, 10:02:42 am
???