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

Author Topic: Draw line  (Read 12093 times)

0 Members and 1 Guest are viewing this topic.

morando

  • Newbie
  • *
  • Posts: 16
    • View Profile
Draw line
« 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Draw line
« Reply #1 on: March 03, 2012, 01:00:18 pm »
Please use the forum search, this question has already been asked several times.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

morando

  • Newbie
  • *
  • Posts: 16
    • View Profile
Draw line
« Reply #2 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Draw line
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

morando

  • Newbie
  • *
  • Posts: 16
    • View Profile
Draw line
« Reply #4 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

morando

  • Newbie
  • *
  • Posts: 16
    • View Profile
Draw line
« Reply #5 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?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Draw line
« Reply #6 on: March 03, 2012, 05:12:49 pm »
Just set the view exactly as it is already is, but flip the Y values :)

KombatWaffle

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Draw line
« Reply #7 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Draw line
« Reply #8 on: December 31, 2012, 03:29:37 pm »
In case you didn't notice, the tutorial is not online yet ;)
Laurent Gomila - SFML developer

KombatWaffle

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Draw line
« Reply #9 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Draw line
« Reply #10 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".

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Draw line
« Reply #11 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything