Hello,
I took a pause from SFML a bit, but i came back to do something briefly.
I wanted to modify colors of a vertexArray randomly.
1. VertexArray is already declared, the vertices positions are known.
2. The function takes the VertexArray as a parameter and modify the vertices colors. Its a "ref".
bool VertexColorREAL(sf::VertexArray &VV )
{
std::size_t cnt=VV.getVertexCount(); ///count
if(cnt==4)
{
sf::Color &c0=VV[0].color;
sf::Color &c1=VV[1].color;
sf::Color &c2=VV[2].color;
sf::Color &c3=VV[3].color;
c0.r = rand() % 255+ 0;
c0.g = rand() % 255+ 0;
c0.b = rand() % 255+ 0;
c1.r = rand() % 255+ 0;
c1.g = rand() % 255+ 0;
c1.b = rand() % 255+ 0;
c2.r = rand() % 255+ 0;
c2.g = rand() % 255+ 0;
c2.b = rand() % 255+ 0;
c3.r = rand() % 255+ 0;
c3.g = rand() % 255+ 0;
c3.b = rand() % 255+ 0;
}
if(cnt==3)
{
//..
}
return true;
}
3. The function checks the number of vertices (if count==4).. etc
Is it possible to work with push_back, to modify only the colors ? I am trying to write something like this :
bool VertexColorREAL(sf::VertexArray &VV )
{
vector<sf::Vertex> vertices;
for(int i=0;i<VV.getVertexCount();i++)
{
&vertices.push_back(sf::Vertex(sf::Color::Black)); // obviousely ERROR
/// I am not quite sure how to do it.
}
-> I am not quite sure how to do it, i don't know if push_back can be used as a setter somehow, the only use i know of is as a constructor, something like this :
vector<sf::Vertex> vertices; /// (VECTOR std c++)
vertices.push_back(sf::Vertex(sf::Vector2f(110.f,110.f),sf::Color::Black));
vertices.push_back(sf::Vertex(sf::Vector2f(210.f,110.f),sf::Color::Yellow));
vertices.push_back(sf::Vertex(sf::Vector2f(210.f,210.f),sf::Color::Blue));
Is there a way to turn around this as a color setter instead of constructors?
Thanks