SFML community forums

Help => Graphics => Topic started by: N1ghtly on April 10, 2012, 02:44:49 pm

Title: Drawing lines in sfml.
Post by: N1ghtly on April 10, 2012, 02:44:49 pm
Hello,

Can someone please explain me how to draw lines? I guess it can be done by creating a 1 px high rectangleshape and rotating it but is there a clena solution for this? I *thought* the was a Line class in SFML but I can't seem to find it.
Title: Re: Drawing lines in sfml.
Post by: eXpl0it3r on April 10, 2012, 02:48:38 pm
You know there's a search function (http://en.sfml-dev.org/forums/index.php?action=search) for this forum (and every other forum you'll ever visit). ;)

Since you're talking about rectangleshape I suppose you're using SFML 2, which is already a good thing.
A line can be done simply with to vertices (sf::Vertex) and a vertex array (sf::VertexArray (http://www.sfml-dev.org/documentation/2.0/classsf_1_1VertexArray.php)).
As primitve type you can choose sf::Lines (http://www.sfml-dev.org/documentation/2.0/group__graphics.php#ga5ee56ac1339984909610713096283b1b).
Title: Re: Drawing lines in sfml.
Post by: thePyro_13 on April 11, 2012, 08:01:36 am
I *thought* the was a Line class in SFML but I can't seem to find it.
The line class was removed; since it didn't do anything that a rotated rectangle couldn't do anyway.
Title: Re: Drawing lines in sfml.
Post by: Jamin Grey on August 02, 2013, 03:08:04 am
Just incase someone doesn't realize thePyro_13 is joking, the old (SFML 1.6) removed function was called:
sf::Shape::Line (http://www.sfml-dev.org/documentation/1.6/classsf_1_1Shape.php#accb884e12dd1a8a55659a220cbbb98c3) and drew a single line slowly.

The new method (SFML 2.x), using sf::VertexArray (http://www.sfml-dev.org/documentation/2.0/classsf_1_1VertexArray.php), as eXpl0it3r mentioned, draws many lines at once (a much faster way to draw, if you're drawing more than one line).
Title: Re: Drawing lines in sfml.
Post by: eXpl0it3r on August 02, 2013, 04:48:30 am
Nice nekroing there... ;D

And no thePyro_13 was not joking. There is not line class in SFML 2.x anymore. The use of vertex array does not equal as a class, so the answer is correct. ;)