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

Author Topic: [SFML 2] Gradient rectangle  (Read 9929 times)

0 Members and 1 Guest are viewing this topic.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
[SFML 2] Gradient rectangle
« on: January 13, 2012, 12:48:27 am »
Is any way for drawing a gradient rectangle of 2 colors using ConvexShape, like I used to do in SFML2(old api)?

Something like this, working against points with colors:
Code: [Select]

sf::Shape m_back;
m_back.AddPoint(0, 0, sf::Color(50, 250, 200));
m_back.AddPoint(800, 0, sf::Color(50, 250, 200));
m_back.AddPoint(800, 600, sf::Color(25, 80, 40));
m_back.AddPoint(0, 600, sf::Color(25, 80, 40));


Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[SFML 2] Gradient rectangle
« Reply #1 on: January 13, 2012, 08:10:25 am »
The sf::Shape classe(s) don't allow to set points color individually anymore, but you can do what you want very easily with vertices:
Code: [Select]
sf::Vertex rectangle[] =
{
    sf::Vertex(point1, color1),
    sf::Vertex(point2, color2),
    sf::Vertex(point3, color3),
    sf::Vertex(point4, color4)
};

window.Draw(rectangle, 4, sf::Quads);
Laurent Gomila - SFML developer

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
[SFML 2] Gradient rectangle
« Reply #2 on: January 13, 2012, 06:56:19 pm »
Okay I understand.
Thanks Laurent.