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 15327 times)

0 Members and 1 Guest are viewing this topic.

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #15 on: July 24, 2013, 02:21:38 pm »
A KISS solution would be just not to use zoom in pixel-art game and leave it for 3D games. It depends on the game design though.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Strange distortion bug when zooming with a sf::View
« Reply #16 on: July 24, 2013, 02:56:20 pm »
A KISS solution would be just not to use zoom in pixel-art game and leave it for 3D games.
Not using the SFML view zooming functionality "for simplicity" is very questionable, I'm sure Octav has his reasons why he needs this feature. There are many use cases even for 2D games.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #17 on: July 24, 2013, 04:01:36 pm »
Yes, but zooming causes graphical glitches in pixel art. He wants to solve it and I just say that not using zoom is the simplest solution - sometimes we forget that we can remove a problematic feature and do great without it.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #18 on: July 24, 2013, 04:13:50 pm »
I wouldn't call "don't zoom" a solution to "how to avoid distortion when using zoom?". :D

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #19 on: July 27, 2013, 04:20:50 pm »
You guys are saying this is normal, but just look at this image.



I want to release a game to a wider audience. Those are horizontal pixels. And no matter what I zoom, it stays distorted, we have tried the smallest scales possible. I have tried everything. There has to be a cause to this, because this is horrible. I spend hours on artwork, and to see it look like this in-game is so terrible :/

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #20 on: July 27, 2013, 04:36:14 pm »
How are you drawing that? VertexArrays? Sprites? Something else?
Back to C++ gamedev with SFML in May 2023

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #21 on: July 27, 2013, 04:38:20 pm »
How are you drawing that? VertexArrays? Sprites? Something else?

VertexArray. Also we tried setSmooth() but it doesn't help much. It still keeps some very ugly distorsion, it just messes it up even more.

void MapLayer::ConstructMap()
{
        mapVertices.clear();

        int index = 0;
        int index_y = 0;

        for(auto&& i : tileData)
        {
                for(auto&& j : i)
                {
                                //====================================================================\\
                                // Figure showing the quad order. Important.                          \\
                                //====================================================================\\
                                //  (up_l_point)    (up_r_point)       |                              \\
                                //        +-----------+                |        (1)    (2)            \\
                                //        |           |                |          +----+              \\
                                //        |           |                |          |    |              \\
                                //        |           |                |          +----+              \\
                                //        |           |                |        (4)    (3)            \\
                                //        +-----------+                |                              \\
                                // (down_l_point)     (down_r_point)   |    Order of the points       \\
                                //====================================================================\\

                                // Declare 4 points of the quad
                                sf::Vertex up_l_point;
                                sf::Vertex up_r_point;
                                sf::Vertex down_r_point;
                                sf::Vertex down_l_point;

                                // Set their positions
                                up_l_point.position =   sf::Vector2f((float)(index*tile_size), (float)(index_y*tile_size));
                                up_r_point.position =   sf::Vector2f((float)(index*tile_size + tile_size), (float)(index_y*tile_size));
                                down_r_point.position = sf::Vector2f((float)(index*tile_size + tile_size), (float)(index_y*tile_size + tile_size));
                                down_l_point.position = sf::Vector2f((float)(index*tile_size), (float)(index_y*tile_size + tile_size));

                                 // Set their texture bounding box
                up_l_point.texCoords =   sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row) * tile_size +0.5f);
                up_r_point.texCoords =   sf::Vector2f((j%tiles_per_row * tile_size) + tile_size-0.5f, (j/tiles_per_row) * tile_size+0.5f);
                down_r_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size + tile_size-0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);
                down_l_point.texCoords = sf::Vector2f((j%tiles_per_row) * tile_size +0.5f, (j/tiles_per_row * tile_size) + tile_size-0.5f);

                                mapVertices.append(up_l_point);
                                mapVertices.append(up_r_point);
                                mapVertices.append(down_r_point);
                                mapVertices.append(down_l_point);

                                index++;
                }
                index = 0;
                index_y++;
        }
}

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #22 on: July 27, 2013, 04:47:55 pm »
Did you try adding and subtracting 0.5 to the positions like you do to textures so that positions too end with 0.5 and tile is tile_size-1.f wide and high?
Back to C++ gamedev with SFML in May 2023

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #23 on: July 27, 2013, 04:53:52 pm »
Did you try adding and subtracting 0.5 to the positions like you do to textures so that positions too end with 0.5 and tile is tile_size-1.f wide and high?

Yes, I tried that as well, and the tile_size is 32x32

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #24 on: July 27, 2013, 04:56:36 pm »
I mean like this so that it'd create 1:1 mapping between coordinates and texture pixels:
// Set their positions
                up_l_point.position =   sf::Vector2f((float)(index*tile_size) + 0.5f, (float)(index_y*tile_size)+0.5f);
                up_r_point.position =   sf::Vector2f((float)(index*tile_size + tile_size)-0.5f, (float)(index_y*tile_size)+0.5f);
                down_r_point.position = sf::Vector2f((float)(index*tile_size + tile_size)-0.5f, (float)(index_y*tile_size + tile_size)-0.5f);
                down_l_point.position = sf::Vector2f((float)(index*tile_size)+0.5f, (float)(index_y*tile_size + tile_size)-0.5f);
Back to C++ gamedev with SFML in May 2023

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #25 on: July 27, 2013, 04:59:38 pm »
I mean like this so that it'd create 1:1 mapping between coordinates and texture pixels:
// Set their positions
                up_l_point.position =   sf::Vector2f((float)(index*tile_size) + 0.5f, (float)(index_y*tile_size)+0.5f);
                up_r_point.position =   sf::Vector2f((float)(index*tile_size + tile_size)-0.5f, (float)(index_y*tile_size)+0.5f);
                down_r_point.position = sf::Vector2f((float)(index*tile_size + tile_size)-0.5f, (float)(index_y*tile_size + tile_size)-0.5f);
                down_l_point.position = sf::Vector2f((float)(index*tile_size)+0.5f, (float)(index_y*tile_size + tile_size)-0.5f);

That seems to produce a better result, however, it also creates a border between the tiles.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #26 on: July 27, 2013, 05:14:35 pm »
 :-\
What about removing all 0.5fs from both textures and positions?
Back to C++ gamedev with SFML in May 2023

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #27 on: July 27, 2013, 05:18:50 pm »
:-\
What about removing all 0.5fs from both textures and positions?

Nope. Still horrible distorsion. Here's the code for my zooming:

if(sf::Keyboard::isKeyPressed(sf::Keyboard::F5) && zoomTimer < 0) {camera.zoom(0.9f); zoomTimer = 0.02f;}
   if(sf::Keyboard::isKeyPressed(sf::Keyboard::F6) && zoomTimer < 0) {camera.zoom(1.1f); zoomTimer = 0.02f;}

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #28 on: July 27, 2013, 05:25:39 pm »
If it renders good with no zoom you could try to render it to a texture that has default view without zooms before drawing it to window with zoomed view, have you tried that?
Back to C++ gamedev with SFML in May 2023

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #29 on: July 27, 2013, 05:35:40 pm »
If it renders good with no zoom you could try to render it to a texture that has default view without zooms before drawing it to window with zoomed view, have you tried that?

I don't quite understand this, however even without a zoom you can notice some strange graphical bugs