SFML community forums

Help => Graphics => Topic started by: Makuto on December 14, 2012, 01:25:20 am

Title: Drawing lines in SFML 2.0
Post by: Makuto on December 14, 2012, 01:25:20 am
How do I draw lines in SFML 2.0? It seems like sf::Shape::Line was removed, so do I just
sf::ConvexShape line;
line.setPointCount(2);
line.setPoint(0, startPoint);
line.setPoint(1, endPoint);
line.setOutlineThickness(5);
win.draw(line);
 

? Is there a better way?
Title: Re: Drawing lines in SFML 2.0
Post by: eXpl0it3r on December 14, 2012, 01:45:15 am
A simple search in the forum would've answered your question in no time. ;)

http://en.sfml-dev.org/forums/index.php?topic=9940.0
http://en.sfml-dev.org/forums/index.php?topic=8649.0
http://en.sfml-dev.org/forums/index.php?topic=7555.0
...

-> use sf::VertexArray with the primitive type sf::Line or sf::LineStrip
Title: Re: Drawing lines in SFML 2.0
Post by: FRex on December 14, 2012, 01:46:08 am
And what you posted shouldn't work because shape checks if it has at least 3 points and it'll not appear when drawn while having less.
Title: Re: Drawing lines in SFML 2.0
Post by: Makuto on December 14, 2012, 01:53:09 am
Yeah, sorry for being lazy

Thanks for the quick response!
Title: Re: Drawing lines in SFML 2.0
Post by: Makuto on December 14, 2012, 03:19:46 am
So, if I need a more dynamic vertex array (ie list instead of vector), what do I do? Store the vertices separately then construct the array at render time? Somehow render individual vertices?
Title: Re: Drawing lines in SFML 2.0
Post by: FRex on December 14, 2012, 03:50:34 am
Not really, you must store them in a vector, vertices are not that hard to copy, they use default copy c-tor and vector might seem bad for erasing elements because it has to move all the others but cpu caches are very good at that and so vectors are better than lists because lists maximize cache misses with random access(accordig to Stroustrup in his presentation about containers, abstraction,c++, moves and threads, should hold true for c++98 I guess). You can also create own wrapper around vector that just swaps the last few with the ones being erased and then pop_back last few to avoid moves of elements at all. This is swap-and-pop-back idiom.
Title: Re: Drawing lines in SFML 2.0
Post by: Makuto on December 14, 2012, 04:43:37 am
Sure I could do that, but how do I actually remove a vertex from the VertexArray at all?
Title: AW: Re: Drawing lines in SFML 2.0
Post by: eXpl0it3r on December 14, 2012, 11:08:56 am
Sure I could do that, but how do I actually remove a vertex from the VertexArray at all?
You don't... ;)
If you want more than sf::VertexArray offers you can use std::vector<sf::Vertex> directly.