SFML community forums

Help => Graphics => Topic started by: morando on March 03, 2012, 12:46:38 pm

Title: Draw line
Post by: morando on March 03, 2012, 12:46:38 pm
Hello everybody, my first post here.  :D

I downloaded SMFL 2.0, looks like thre is no interface to draw Line shape?
Since i am noob, what can i do? Derive from sf::Shape?

Thanks for your time.
Title: Draw line
Post by: Nexus on March 03, 2012, 01:00:18 pm
Please use the forum search, this question has already been asked several times.
Title: Draw line
Post by: morando on March 03, 2012, 01:11:41 pm
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:

Code: [Select]

#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.
Title: Draw line
Post by: Nexus on March 03, 2012, 01:34:28 pm
Quote from: "morando"
I am sorry, but i used search before posting my question and could not find nothing with "draw line" keywords.
You didn't look exactly at the results. Using this search keywords, the threads "Line shape" and "Create a line segment shape in sfml 2.0?" are listed.

Maybe you should check the option "Search for all terms", I can't understand why this is not the default anyway.
Title: Draw line
Post by: morando on March 03, 2012, 01:46:38 pm
Found it!!!  :D

Thanks for your help, pointing into right search keywords.

http://www.sfml-dev.org/forum/viewtopic.php?p=42814&highlight=rectangleshape#42814
Title: Draw line
Post by: morando on March 03, 2012, 02:09:31 pm
To use same thread for another stupid question.  :oops:

How can i setup view so that +Y axis is going from down-up, and X axis to stay same?
Title: Draw line
Post by: Grimshaw on March 03, 2012, 05:12:49 pm
Just set the view exactly as it is already is, but flip the Y values :)
Title: Re: Draw line
Post by: KombatWaffle on December 31, 2012, 03:28:00 pm
If this questions gets asked that many times, perhaps you guys should put it into the actual tutorials, instead of barking at people for asking it.
Title: Re: Draw line
Post by: Laurent on December 31, 2012, 03:29:37 pm
In case you didn't notice, the tutorial is not online yet ;)
Title: Re: Draw line
Post by: KombatWaffle on December 31, 2012, 04:23:05 pm
That was my point.

If it's not to be found within the tutorial section, don't be surprised when the question comes up.

The guy Nexus who responded here could've either wasted his time on one post answering the OP, or just giving him a link. Instead he wasted his oh-so-precious time posting once, doing a search himself, then posting a second time just to make a point.

I'm not saying he was wrong in his point. Doing a search is easier. And this thread was the first result that came up when I googled "sfml 2.0 draw line." But had he just answered, I would've gotten my answer too, instead I had to go through another layer of clicking links to finally find an answer, embedded somewhere in a thick thread.

I'm just saying that if something comes up frequently, maybe it's not always the other guys' fault.
Title: Re: Draw line
Post by: G. on December 31, 2012, 04:28:47 pm
Well, maybe people are getting tired of answering the same thing over and over. The answer can be found with an easy search, so it's basically "do the search for me".
Title: Re: Draw line
Post by: eXpl0it3r on December 31, 2012, 05:34:29 pm
I'm just saying that if something comes up frequently, maybe it's not always the other guys' fault.
SFML 2.0 is still not official so you can't expect the tutorials to be uptodate and as has been mentioned they are in the process of making.
And if people would only use the search function, they wouldn't have to ask that often, so in that sense, yes it's their fault for not using the search function. ;)