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

Author Topic: Pixel deformation while moving sprites  (Read 2101 times)

0 Members and 1 Guest are viewing this topic.

Shadow Kitsune

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Pixel deformation while moving sprites
« on: February 07, 2022, 03:23:54 pm »
Ok so when I move my sprite, sometimes the pixels get smaller and wider in width. Just a little bit.
It only happens when the view is resized(I resize it by factor of 1.2 or 0.8). Question is - Can I somehow get rid of that behavior?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11037
    • View Profile
    • development blog
    • Email
Re: Pixel deformation while moving sprites
« Reply #1 on: February 07, 2022, 04:39:43 pm »
Render on integer/pixel coordinates and don't scale your view (or only scale it by factors of 2).

The issue is once you tell OpenGL to render something that is smaller than a pixel, it has to do some interpolation and decide how it should render this small pixel, which then can lead to behavior as described.
By sticking to integer coordinates, OpenGL doesn't have to interpolate, and no unwanted distortions appear.

Some effects can be mitigated with a render texture that is used before rendering to the screen, but it won't solve everything.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Shadow Kitsune

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Pixel deformation while moving sprites
« Reply #2 on: February 07, 2022, 04:50:47 pm »
Well yes, but I need to scale it by some float factor in order to match resolution, or I would need to work on 320 x 180 window to scale it properly using int values.

Or am I doing something wrong in here and need to rework my resolution system?