I am sorry, but i used search before posting my question and could not find nothing with "draw line" keywords.
I tried this but nothing displayed:
#include <iostream>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")
#pragma comment(lib, "sfml-audio-d.lib")
class Line : public sf::Shape
{
private:
sf::Vector2f pt[4];
public:
Line(const sf::Vector2f& pt1, const sf::Vector2f& pt2, float thick = 1.0f)
{
pt[0] = pt1 - sf::Vector2f((thick / 2.0f), (thick / 2.0f));
pt[1] = pt1 + sf::Vector2f((thick / 2.0f), (thick / 2.0f));
pt[2] = pt2 + sf::Vector2f((thick / 2.0f), (thick / 2.0f));
pt[3] = pt2 - sf::Vector2f((thick / 2.0f), (thick / 2.0f));
SetFillColor(sf::Color(255, 255, 255, 255));
}
unsigned int GetPointCount() const
{
return 4;
}
sf::Vector2f GetPoint(unsigned int index) const
{
return pt[index];
}
};
int main()
{
try
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
Line line = Line(sf::Vector2f(0.0f, 0.0f), sf::Vector2f(50.0f, 50.0f), 4.0f);
while (window.IsOpen())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}
window.Clear();
window.Draw(line);
window.Display();
}
}
catch(const std::runtime_error& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
I am really sorry but i am new to SMFL and C++.
Thanks for your time.
EDIT: Please, if you find time to point me to some of the topics about lines, i still can't find one.
Also, i have trouble to build quad given two points to simulate line, how should i calculate corner points?
And, in what order (CW or CCW) these points to be created?
Thanks in advance for your patience.