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

Author Topic: Sprite::Scale() throws off position  (Read 3239 times)

0 Members and 1 Guest are viewing this topic.

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
Sprite::Scale() throws off position
« 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~

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Sprite::Scale() throws off position
« Reply #1 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
Sprite::Scale() throws off position
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::Scale() throws off position
« Reply #3 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.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Sprite::Scale() throws off position
« Reply #4 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. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::Scale() throws off position
« Reply #5 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.
Laurent Gomila - SFML developer

Chebastian

  • Newbie
  • *
  • Posts: 1
    • View Profile
Sprite::Scale() throws off position
« Reply #6 on: October 13, 2011, 09:52:45 am »
hows it going with this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::Scale() throws off position
« Reply #7 on: October 13, 2011, 10:02:42 am »
???
Laurent Gomila - SFML developer

 

anything