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

Author Topic: Drawing lines in SFML 2.0  (Read 5402 times)

0 Members and 1 Guest are viewing this topic.

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Drawing lines in SFML 2.0
« 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?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Drawing lines in SFML 2.0
« Reply #1 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Drawing lines in SFML 2.0
« Reply #2 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.
Back to C++ gamedev with SFML in May 2023

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Re: Drawing lines in SFML 2.0
« Reply #3 on: December 14, 2012, 01:53:09 am »
Yeah, sorry for being lazy

Thanks for the quick response!
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Re: Drawing lines in SFML 2.0
« Reply #4 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?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Drawing lines in SFML 2.0
« Reply #5 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.
Back to C++ gamedev with SFML in May 2023

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Re: Drawing lines in SFML 2.0
« Reply #6 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?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: Drawing lines in SFML 2.0
« Reply #7 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/