I'm not sure why the 'gaps' appear when I'm using the code below. At first I thought perhaps it might be some float rounding thing, but that doesn't seem to be the case.
You can see the gaps (black lines) here:
Here is the (minimal, compilable) code that produces it on my system. You'll have to pardon the naming style mismatch.
#include <SFML/Graphics.hpp>
const unsigned win_height = 600 ;
const unsigned win_width = 800 ;
const unsigned line_height = 300 ;
void draw_vertical_line(sf::RenderTexture& t, unsigned x) ;
void update_texture(sf::RenderTexture& t) ;
void wait_for_close(sf::RenderWindow& window) ;
int main()
{
sf::RenderWindow window(sf::VideoMode(win_width, win_height), "Vertical Lines") ;
sf::RenderTexture texture ;
if (texture.create(win_width, win_height))
{
update_texture(texture) ;
window.clear() ;
window.draw(sf::Sprite(texture.getTexture())) ;
window.display() ;
}
wait_for_close(window) ;
}
void draw_vertical_line(sf::RenderTexture& t, unsigned x)
{
sf::VertexArray line(sf::Lines, 2) ;
line[0].position = sf::Vector2f(x, win_height) ;
line[1].position = sf::Vector2f(x, win_height - line_height) ;
line[0].color = line[1].color = sf::Color(0, 255, 256 * x / win_width) ;
t.draw(line) ;
}
void wait_for_close(sf::RenderWindow& window)
{
sf::Event event ;
while (window.isOpen())
while ( window.pollEvent(event) )
if ( event.type == sf::Event::Closed )
window.close() ;
}
void update_texture(sf::RenderTexture& t)
{
t.clear() ;
for ( unsigned i=0; i<win_width; ++i)
draw_vertical_line(t, i) ;
t.display() ;
}
Can anyone see what I'm doing wrong here?