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

Author Topic: Changing Line Color?  (Read 9959 times)

0 Members and 1 Guest are viewing this topic.

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Changing Line Color?
« on: February 02, 2013, 10:54:33 pm »
So after some searching I found out how to draw a line...

sf::Vertex line[2] = {sf::Vector2f(x1,y1), sf::Vector2f(x2,y2)};
screen.draw(line , 2, sf::Lines);

OK easy enough, however this draws a white line. What if I want a line of a certain color or with a certain amount of transparency? I noticed RenderTexture.draw takes a another parameter, renderstate, from the documentation. Can someone explain how I might go about this. I've looked at the documentation for renderstate but still don't understand how I would go about using it in this case, if you use it at all.

Thanks for any help you can give
-Sam

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Changing Line Color?
« Reply #1 on: February 02, 2013, 11:09:31 pm »
The above version only uses the position component of vertices. But vertices can have a color as well:

sf::Vertex line[2] =
{
    sf::Vertex(sf::Vector2f(x1, y1), color),
    sf::Vertex(sf::Vector2f(x2, y2), color)
};
screen.draw(line , 2, sf::Lines);
Laurent Gomila - SFML developer

Solluxx

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Changing Line Color?
« Reply #2 on: February 03, 2013, 07:33:03 am »
Haha it looks great, ty! ;D