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[]);
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));