hey, im beginner in sfml and here i want draw one vertex between two points but when i call window.draw(lines); I get an error: Use undeclared identifier "lines"
what should i do?
thanks
sf::RenderWindow window(sf::VideoMode(600, 400), "Convex Hull");
std::vector<sf::RectangleShape> rects;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event) )
{
if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::MouseButtonPressed &&
event.mouseButton.button == sf::Mouse::Left&&
rects.size() < 10) {
posx.push_back(event.mouseButton.x);
posy.push_back(event.mouseButton.y);
// cout << posx[f] << " " << posy[f] << endl;
f++;
// cout << f << endl;
sf::RectangleShape rect { { 2, 2 } };
rect.setPosition(sf::Vector2f(sf::Mouse::getPosition(window)));
rect.setFillColor(sf::Color::Green);
rects.push_back(rect);
cout << &rects << endl;
sf::VertexArray lines(sf::LinesStrip, 2);
lines[0].position = sf::Vector2f(posx[0], posy[0]);
lines[1].position = sf::Vector2f(posx[10], posy[10]);
}
if (f == 10)
break;
}
window.clear();
for (const auto &r : rects)
window.draw(r);
window.draw(lines); // Error is here
window.display();
}