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

Author Topic: Add vertices to a vector  (Read 2601 times)

0 Members and 1 Guest are viewing this topic.

kirilzh

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Add vertices to a vector
« on: April 24, 2018, 02:30:13 am »
I'm trying to draw about a hundred lines on the screen. So far I'm testing my code with adding only two vertices to a vector but the code won't compile because of

error: expected primary-expression before ']' token vertices.push_back(line[]);

I'm not really experienced in C++ and any help would be greatly appreciated.

Here's my code so far.

    std::vector <sf::Vertex> vertices;

    sf::Vertex line[] =
    {
        sf::Vertex(sf::Vector2f(1, 0), sf::Color::Red),
        sf::Vertex(sf::Vector2f(1, 150), sf::Color::Green),
    };

    sf::Vertex line2[] =
    {
        sf::Vertex(sf::Vector2f(3, 0), sf::Color::Red),
        sf::Vertex(sf::Vector2f(3, 150), sf::Color::Green)
    };

    vertices.push_back(line[]);
    vertices.push_back(line2[]);

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Add vertices to a vector
« Reply #1 on: April 24, 2018, 04:29:26 am »
A good place to start would be the tutorials.
You should also read a good book for improving your C++ knowledge.
Failing to succeed does not mean failing to progress!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Add vertices to a vector
« Reply #2 on: April 24, 2018, 07:56:32 am »
Yes, that's a basic C++ question not related to SFML, so you'd better improve your C++ skills first (by reading some good documentation, preferably a book) :)

Don't make things more complicated than they should be, just add the vertices directly to the vector:
vertices.push_back(sf::Vertex(sf::Vector2f(1, 0), sf::Color::Red));
vertices.push_back(sf::Vertex(sf::Vector2f(1, 150), sf::Color::Green));
vertices.push_back(sf::Vertex(sf::Vector2f(3, 0), sf::Color::Red));
vertices.push_back(sf::Vertex(sf::Vector2f(3, 150), sf::Color::Green));
Laurent Gomila - SFML developer

 

anything