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

Author Topic: Drawing a std::vector<sf::Vector2f> like a VertexArray  (Read 2130 times)

0 Members and 1 Guest are viewing this topic.

vanpet

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Drawing a std::vector<sf::Vector2f> like a VertexArray
« on: October 30, 2012, 07:24:32 pm »
I'm new to graphic programming in general, so my questions may seem stupid, please excuse me, but I swear I'm doing my best to read and understand most of the documentation (-> not easy for me)!

Until now, I've played with VertexArray to draw complex polygons, and it was fine. But now, I need to edit these shapes (for example, the user must be able to add a point between to other points), and I don't think I can use VertexArray to insert a point in the middle because it has only push_back method at the end of the array.

So, now I made my own class Polygon and I store the points in a vector<sf::Vector2f>

In my class Polygon, I inherited Drawable, and I want to make a virtual draw function to handle the drawing of my Polygon...

virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

Unfortunately, I have no idea how to implement this function. I don't know how to go from my vector to a drawable object like a vertexArray.

Foolishly, I tried to use low level OpenGL instructions, but it was a big mess and I guess I feel more confortable staying in the SFML world for the moment.

Can someone please push me in the right direction? I suppose the answer is easy for you!

Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing a std::vector<sf::Vector2f> like a VertexArray
« Reply #1 on: October 30, 2012, 07:46:48 pm »
Instead of storing an array of sf::Vector2f, you could directly store an array of sf::Vertex, which can be rendered directly. Otherwise you'll have to do the conversion every time you want to draw it, which would be very inefficient.
Laurent Gomila - SFML developer

vanpet

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: Drawing a std::vector<sf::Vector2f> like a VertexArray
« Reply #2 on: October 30, 2012, 08:06:20 pm »
Thanks!

 

anything