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

Author Topic: [SOLVED] Strange distortion bug when zooming with a sf::View  (Read 18151 times)

0 Members and 1 Guest are viewing this topic.

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
SOLUTION IS ON PAGE 3

I have had this bug for a while, but all my attempts to fix it have been null. I have a simple sf::View set up as a member of the player class, and here's some bits of code:

Game.cpp:
player -> Camera = window.getDefaultView();

Player.cpp:

void Player::updateCamera()
{
        Camera.setCenter(pos); // pos is the position of the player
}

However when I zoom in the game, some pixels look distorted, you can see thin lines, wave pattern at the floor where there's only straight lines, etc.

« Last Edit: July 27, 2013, 10:24:12 pm by Octav »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #1 on: July 22, 2013, 08:02:29 am »
It's hard to keep a pixel perfect rendering in this case: your world units no longer match the window's pixels, so OpenGL has to distort things to compensate.

There's no easy workaround, unfortunately. What you can do is to try different sizes for your view, and maybe you'll notice a rule for sizes that produce artifacts (typically, that would be non-integer or odd sizes), and avoid them.
Laurent Gomila - SFML developer

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #2 on: July 22, 2013, 11:24:43 am »
It's hard to keep a pixel perfect rendering in this case: your world units no longer match the window's pixels, so OpenGL has to distort things to compensate.

There's no easy workaround, unfortunately. What you can do is to try different sizes for your view, and maybe you'll notice a rule for sizes that produce artifacts (typically, that would be non-integer or odd sizes), and avoid them.

I see, would there be any drastic change that I could do to keep a certain ratio in things? Surely someone must have had this problem before or there must be a cause

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #3 on: July 22, 2013, 06:27:59 pm »
I forgot an important detail, which could be the problem!

My tiles are all 30x30. I'll try to make them 32x32 and get back to this thread to post the solution.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #4 on: July 22, 2013, 07:20:23 pm »
Distortions are unavoidable.
If your tiles are 32*32, when you zoom they are maybe displayed as 38*38, that's 6 rows and columns of new pixels so obviously the pixel patterns can't be the same.

You could allow only zoom values that keeps the pixel ratio where 32*32 tiles would become 64*64, then 96*96, etc. Pixel patterns would stay intact.

Or you could try to smooth them (using sf::Texture::setSmooth) but you may not like it.

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #5 on: July 22, 2013, 08:26:16 pm »
OK I set the textures to 32:32, still the same distortion bug

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #6 on: July 22, 2013, 08:58:30 pm »
There is literally no zoom level that actually doesn't make things distorted, I tried everything. Does anyone know the cause, or maybe a fix? :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #7 on: July 22, 2013, 09:11:12 pm »
Quote
There is literally no zoom level that actually doesn't make things distorted
An exact x2 zoom doesn't give a perfect result?
Laurent Gomila - SFML developer

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #8 on: July 22, 2013, 10:29:36 pm »
Quote
There is literally no zoom level that actually doesn't make things distorted
An exact x2 zoom doesn't give a perfect result?

We have tried all sorts of methods, including just using a precise setSize, and we've set a very small scale for zooming so that we can find a good non-distorted version of the game as well but no results. We've tried zooming for a specific factor, like 2x, 3x, etc, but still, there is a noticeable distorsion. Changing the texture size to 32x32 did make things appear a bit better, but not by much.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #9 on: July 22, 2013, 10:47:05 pm »
You should try to reproduce this problem in a minimal app (just a sprite and a view). This way I (and others) can test it easily.
Laurent Gomila - SFML developer

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #10 on: July 23, 2013, 03:58:39 pm »
Okay, I've managed to reproduce this bug on a very small scale, it's not as serious as in the game but it's the same bug, you can clearly see a distortion when you zoom in or out. I didn't want to include our whole map system so I just made it load a picture of a map. I know it's not the same as a vertexarray, but it's as minimal as I can get.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #11 on: July 23, 2013, 05:59:47 pm »
I tested your code and I can't reproduce unexpected results.

The result is sometimes not a 1:1 rendering of the original image, but that's clearly because of what G. said.

Quote
If your tiles are 32*32, when you zoom they are maybe displayed as 38*38, that's 6 rows and columns of new pixels so obviously the pixel patterns can't be the same.

So, on my side, everything is ok.
Laurent Gomila - SFML developer

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #12 on: July 24, 2013, 10:41:17 am »
Alright, I just thought that it wasn't supposed to be like that, because when I make the artwork and see it a bit distorted it ruins some of my plans.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #13 on: July 24, 2013, 11:54:15 am »
Activating linear filtering (texture.setSmooth(true)) might give a better (smoother) result, but it would also ruin your pixel art.
Laurent Gomila - SFML developer

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #14 on: July 24, 2013, 01:33:47 pm »
We tried that, and it works, I'm not sure if we'll use the smoothening, we might just keep this small distortion right now, we're only worried because we plan to commercialize the game

 

anything