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

Author Topic: Drawing vertexArray getting unexpected lines of pixls that are of unknown origin  (Read 3310 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Hello.
I have a vertexArray that has sf::Quads made in squares to represent 32x32 pixels.
The issue is when i am moving around the vertexArray using sf::transform, and it always happens when i pass in a float value of(x.5) x being any value.

Image as expected
http://postimg.org/image/ymzl93ead/
When moving at one frame this is dispalyed
http://postimg.org/image/j2s7ik45x/

Ever had this happen to someone?
What is the fix for the solution? it is really eye catching when moving map around and it cant be tolerated.
One solution is to check if i am passing (x.5) intro the translate and add or remove (x.1) but i find that not being global solution to issue.
Is behavior like this intent or did i make a mistake?
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Displaying things at non-integer coordinates is always a bit weird, but do you really need to do that anyway?  Why not just round to the nearest integer coordinates?

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
When its not float, it seems as it is screan tearing all the time.
With VSync and or limited fps to my screen i get weird look...
Somehow edges of "Color change" flicker and have different color"
So for example, imagine a 50x50 blocks of white and black going in chess board patern over whole screen,
when moving the screen around at 1 pixel per frame, the edges of color difference are having different colors then the ones i set them to have.
edges pixels of black block have gray on it... while white have the same issue.
With black & green, only the green is distorted and it gets whiter green then it should have.
I have tried to get screen of what i am experiencing but i just cant get it...

EDITED.

Anywhere a example how to move vertex array around without issue like this so i can test.
Somehow i do not think its sfml issue maybe my graphics card is, or something.
« Last Edit: September 01, 2013, 10:35:41 am by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Maybe you could write an example of what you're currently doing and we might suggest improvement up on it. Remember only to provide the relevant and minimal, but still complete code. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Working on it since i posted last post.
Having issue atm.

Texture http://postimg.org/image/8pfoen5kh/
With this code the movement of the map is jumpy, cant reproduce the issue of blur
int main()
{
        sf::Texture tex;
        tex.loadFromFile("img.png");

        sf::VertexArray arr;
        arr.setPrimitiveType(sf::PrimitiveType::Quads);
        arr.resize(5*5*4);
        bool color = false;
        for(int y = 0; y < 5; y++)
        {
                for(int x = 0; x < 5; x++)
                {
                        arr[(x + (y*5))*4+0].position = sf::Vector2f(x*32, y*32);
                        arr[(x + (y*5))*4+1].position = sf::Vector2f(x*32+32, y*32);
                        arr[(x + (y*5))*4+2].position = sf::Vector2f(x*32+32, y*32+32);
                        arr[(x + (y*5))*4+3].position = sf::Vector2f(x*32, y*32+32);
                       
                        if(color == false)
                        {
                                arr[(x + (y*5))*4+0].texCoords = sf::Vector2f(0*32, 0*32);
                                arr[(x + (y*5))*4+1].texCoords = sf::Vector2f(0*32+32, 0*32);
                                arr[(x + (y*5))*4+2].texCoords = sf::Vector2f(0*32+32, 0*32+32);
                                arr[(x + (y*5))*4+3].texCoords = sf::Vector2f(0*32, 0*32+32);
                        }
                        else
                        {
                                arr[(x + (y*5))*4+0].texCoords = sf::Vector2f(1*32, 0*32);
                                arr[(x + (y*5))*4+1].texCoords = sf::Vector2f(1*32+32, 0*32);
                                arr[(x + (y*5))*4+2].texCoords = sf::Vector2f(1*32+32, 0*32+32);
                                arr[(x + (y*5))*4+3].texCoords = sf::Vector2f(1*32, 0*32+32);
                        }
                       
                        color = !color;
                }
        }

        int posX = 0, posY = 0;

        sf::RenderStates state;
        state.texture = &tex;
        sf::Transform transform;
        transform.translate(posX, posY);
        state.transform = transform;
        state.blendMode = sf::BlendMode::BlendNone;

        sf::RenderWindow renWin;
        renWin.create(sf::VideoMode(800,600,32), "This is not the best song in the world, this is just a tribbute");
        renWin.setFramerateLimit(60);

        while(renWin.isOpen())
        {
                sf::Event event;
                while(renWin.pollEvent(event))
                {
                        switch(event.type)
                        {
                        case sf::Event::Closed:
                                renWin.close();
                                break;

                        case sf::Event::KeyPressed:
                                switch(event.key.code)
                                {
                                case sf::Keyboard::W:
                                        posY -= 1;
                                        break;
                                case sf::Keyboard::S:
                                        posY += 1;
                                        break;
                                case sf::Keyboard::A:
                                        posX -= 1;
                                        break;
                                case sf::Keyboard::D:
                                        posX += 1;
                                        break;
                                default:
                                        break;
                                }
                                break;

                        default:
                                break;
                        }
}
                        sf::RenderStates state;
                        state.texture = &tex;
                        sf::Transform transform;
                        transform.translate(posX, posY);
                        state.transform = transform;
                        state.blendMode = sf::BlendMode::BlendNone;

                        renWin.draw(arr, state);
                        renWin.display();
                        renWin.clear();
               
        }
        return 0;
}

EDIT::: THIS CODE HAS A MASSIVE FLAW.
Each event loop was bad.
i had all logic in event loop. FIXED NOW

Can you link me to a proper window with vertexArray using texture array so i test that.
I have just too complicated code to pluck it out and post it
« Last Edit: September 01, 2013, 12:24:16 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
You can read the official tutorial about vertex arrays, it explains the usage very well.

By the way, your code is unnecessarily complicated:
            if(color == false)
            {
                arr[(x + (y*5))*4+0].texCoords = sf::Vector2f(0*32, 0*32);
                arr[(x + (y*5))*4+1].texCoords = sf::Vector2f(0*32+32, 0*32);
                arr[(x + (y*5))*4+2].texCoords = sf::Vector2f(0*32+32, 0*32+32);
                arr[(x + (y*5))*4+3].texCoords = sf::Vector2f(0*32, 0*32+32);
            }
            else
            {
                arr[(x + (y*5))*4+0].texCoords = sf::Vector2f(1*32, 0*32);
                arr[(x + (y*5))*4+1].texCoords = sf::Vector2f(1*32+32, 0*32);
                arr[(x + (y*5))*4+2].texCoords = sf::Vector2f(1*32+32, 0*32+32);
                arr[(x + (y*5))*4+3].texCoords = sf::Vector2f(1*32, 0*32+32);
            }

First, instead of color == false you can write !color, and second, you can combine the statements by using a variable for 0 and 1 (or even color itself, exploiting the conversion from bool to int). Third, the index (x + (y*5))*4 is needlessly repeated, which can be avoided with a std::size_t variable.

Apart from that: sf::BlendMode::BlendNone is not valid C++03, only valid C++11. For non-scoped enums, I would still recommend to write sf::BlendNone, since the enumerators are spread in the sf namespace anyway.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
I have bean working over 3-4 hours on this issue so far, i have figured out so far.
1: I am unable to reproduce the issue in small scale.
2: I am unable to locate the issue when using large scare(Copied part by part from a project where i done get such a error and i don't get the jiggering and flickering of edge pixels)
3: Retyped, also tried copying from other project a copy of code for each part that is in touch with the VertexArray, RenderWindow, Texture, Loading vertexArray...
I will try to give it another try later in the week, maybe i am overseeing something big.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Using floats will almost always cause those weird lines to appear, stick with whole integers. 

Also using textures that are a power of 2(2, 4, 8, 16, 32, 64, 128...) may yeild non'weird' results as graphics cards generally made to handle textures with power of 2 way easier and better than non standard texture sizes.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Minimal example for the issue i am experiencing:

While holding "A" on keyboard, on far right side of the square that is being drawn there is one vertical line of pixels that is brighter then it is supposed to be(as in in texture)
While holding "D" on keyboard, on far left side of the square that is being drawn there is one vertical line of pixels that is brighter then it is supposed to be...

Texture used
"http://postimg.org/image/wj5onh7e5/"

int main()
{
        sf::VertexArray arr;
        arr.setPrimitiveType(sf::PrimitiveType::Quads);
        arr.resize(4*4*4);
        for(int y = 0; y < 4; y++)
        {
                for(int x = 0; x < 4; x++)
                {
                        arr[(x+(y*4))*4+0].position = sf::Vector2f(x*32+0, y*32+0);
                        arr[(x+(y*4))*4+1].position = sf::Vector2f(x*32+32, y*32+0);
                        arr[(x+(y*4))*4+2].position = sf::Vector2f(x*32+32, y*32+32);
                        arr[(x+(y*4))*4+3].position = sf::Vector2f(x*32+0, y*32+32);

                        arr[(x+(y*4))*4+0].texCoords = sf::Vector2f(0+0, 0+0);
                        arr[(x+(y*4))*4+1].texCoords = sf::Vector2f(0+32, 0+0);
                        arr[(x+(y*4))*4+2].texCoords = sf::Vector2f(0+32, 0+32);
                        arr[(x+(y*4))*4+3].texCoords = sf::Vector2f(0+0, 0+32);
                }
        }

        sf::Texture tex;
        tex.loadFromFile("img.png");

        sf::RenderStates state;
        state.texture = &tex;

        sf::RenderWindow win;
        win.create(sf::VideoMode(640,480,32), "game");
        win.setFramerateLimit(60);

        sf::View view;
        view.reset(sf::FloatRect(0, 0, 640, 480));

        while(win.isOpen())
        {
                sf::Event event;
                while(win.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                                win.close();
                        if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::A)
                                view.move(-1, 0);
                        if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::D)
                                view.move(1, 0);
                }
                win.setView(view);
                win.draw(arr, state);
                win.display();

                win.clear();
        }

    return 0;
}
 

Using floats will almost always cause those weird lines to appear, stick with whole integers. 

Also using textures that are a power of 2(2, 4, 8, 16, 32, 64, 128...) may yeild non'weird' results as graphics cards generally made to handle textures with power of 2 way easier and better than non standard texture sizes.
Ive bean reading on how openGL, graphics work on drawing since i was suspecting that it was my GPU issue not the SFML.
Those suggestions are great for someone of my knowledge(i should read up more)!

You can read the official tutorial about vertex arrays, it explains the usage very well.

By the way, your code is unnecessarily complicated:
            if(color == false)
            {
                arr[(x + (y*5))*4+0].texCoords = sf::Vector2f(0*32, 0*32);
                arr[(x + (y*5))*4+1].texCoords = sf::Vector2f(0*32+32, 0*32);
                arr[(x + (y*5))*4+2].texCoords = sf::Vector2f(0*32+32, 0*32+32);
                arr[(x + (y*5))*4+3].texCoords = sf::Vector2f(0*32, 0*32+32);
            }
            else
            {
                arr[(x + (y*5))*4+0].texCoords = sf::Vector2f(1*32, 0*32);
                arr[(x + (y*5))*4+1].texCoords = sf::Vector2f(1*32+32, 0*32);
                arr[(x + (y*5))*4+2].texCoords = sf::Vector2f(1*32+32, 0*32+32);
                arr[(x + (y*5))*4+3].texCoords = sf::Vector2f(1*32, 0*32+32);
            }

First, instead of color == false you can write !color, and second, you can combine the statements by using a variable for 0 and 1 (or even color itself, exploiting the conversion from bool to int). Third, the index (x + (y*5))*4 is needlessly repeated, which can be avoided with a std::size_t variable.

Apart from that: sf::BlendMode::BlendNone is not valid C++03, only valid C++11. For non-scoped enums, I would still recommend to write sf::BlendNone, since the enumerators are spread in the sf namespace anyway.
I noticed error appeared when those two colors where mixed so i tried something fast, on top of my mind and easily readable. I will comment the code next time.
« Last Edit: September 02, 2013, 01:32:54 am by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Bump.
Can anyone check if the code last posted causes issues that where described on other systems pretty please.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0