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

0 Members and 2 Guests are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #30 on: July 27, 2013, 05:40:19 pm »
I don't quite understand this, however even without a zoom you can notice some strange graphical bugs
Then I really start to doubt, that it's an issue with SFML/OpenGL.
Are your graphics driver uptodate?

Can you put together a minimal and complete example that reproduces the problem, so we can test it on our own and see if it's related to your hardware, a mistake in the code or an actual OpenGL issue.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Strange distortion bug when zooming with a sf::View
« Reply #31 on: July 27, 2013, 05:47:45 pm »
Can you try it with sf::Sprite, just to make sure there is no mistake in the computation of your texture and vertex coordinates?

Test it with the following code, store a single tile in the file "tile.png":
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application");
        window.setFramerateLimit(20);

        sf::Texture texture;
        texture.loadFromFile("tile.png");

        sf::Sprite sprite(texture);
        const float tileSize = texture.getSize().x;

        sf::View view = window.getDefaultView();

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                return 0;

                        if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::F)
                                        view.zoom(1.f/0.9f);
                                else if (event.key.code == sf::Keyboard::D)
                                        view.zoom(0.9f);
                                else if (event.key.code == sf::Keyboard::Escape)
                                        return 0;
                        }
                }

                window.setView(view);
                window.clear();
               
                for (unsigned int x = 0; x < 10; ++x)
                {
                        for (unsigned int y = 0; y < 10; ++y)
                        {
                                sprite.setPosition(x * tileSize, y * tileSize);
                                window.draw(sprite);
                        }
                }

                window.display();
        }
}

You're aware that by using this approach, there will be rounding errors for the zoom? You should recompute the zoom factor based on an integer level, so that it is truly reversible.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #32 on: July 27, 2013, 06:01:41 pm »
I don't quite understand this, however even without a zoom you can notice some strange graphical bugs
Are your graphics driver uptodate?

Yes, and I don't work alone on this project, and my teammate and other people have had the same distorsion bug.

I don't quite understand this, however even without a zoom you can notice some strange graphical bugs
Can you put together a minimal and complete example that reproduces the problem, so we can test it on our own and see if it's related to your hardware, a mistake in the code or an actual OpenGL issue.

I already have, and it only uses a simple sprite, check page 1
« Last Edit: July 27, 2013, 06:03:14 pm by Octav »

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #33 on: July 27, 2013, 06:04:08 pm »
Alright a person told me that for him, my code works fine, but he is using SFML 2.1 and I am using the old version. I will try to install 2.1 and get back to this thread.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Strange distortion bug when zooming with a sf::View
« Reply #34 on: July 27, 2013, 07:12:09 pm »
I already have, and it only uses a simple sprite, check page 1
Oh I was looking for a code section and not a attachment. :D

Anyways, it works fine on my PC (AMD Radeon 7xxxM series) - except the obvious distortion when zooming out, due to the fact that not all pixel can be represented anymore.
I'm using my Nighlty Build, which is currently the same as SFML 2.1.





Test it with the following code, store a single tile in the file "tile.png":
Works fine here as well.
« Last Edit: July 27, 2013, 07:14:38 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Octav

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Strange distortion bug when zooming with a sf::View
« Reply #35 on: July 27, 2013, 07:18:35 pm »
Fixed it.

Earlier, I had this code:
 // 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);

And removing 0.5f did the trick. Apparently that kills the whole thing. It wasn't a bug with the camera, it was a bug with the way I programmed the vertexarray. It looks perfect now. Thanks a lot everyone!

FRex

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

Nope. Still horrible distorsion.(...)
*grumble grumble*  >:(
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 #37 on: July 27, 2013, 08:30:27 pm »
:-\
What about removing all 0.5fs from both textures and positions?

Nope. Still horrible distorsion.(...)
*grumble grumble*  >:(

I'm sorry about that, silly mistake, because I didn't add the 0.5f and I didn't realize it was added to the X and Y coords. That position has two sizes, and I was only deleting the ones at the end, silly mistake  ;D