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.