Hello.
I am having problem using the sf::VertexArray object.
I am going to use it to render multiple snowflakes in one draw call and therefore I need every flake to have its own 4 vertices in the sf::VertexArray.
And so every snowflake needs to know each own sf::Vertex* quad array, but when I pass the sf::Vertex* to the snowflake, the array becomes invalid.
This is when I add a flake.
void Snowy::createFlake()
{
int textureId = thor::random(0, 3);
sf::Vertex v0, v1, v2, v3;
v0.texCoords = sf::Vector2f(16 * textureId, 0);
v1.texCoords = sf::Vector2f(16 * textureId + 16, 0);
v2.texCoords = sf::Vector2f(16 * textureId + 16, 16);
v3.texCoords = sf::Vector2f(16 * textureId, 16);
m_vertices.append(v0);
m_vertices.append(v1);
m_vertices.append(v2);
m_vertices.append(v3);
sf::Vertex* verts = &m_vertices[m_vertices.getVertexCount() - 4]; // This seems to become invalid when I use it in the snowflake update function
SnowFlake flake(verts);
flake.setX(thor::random(0, m_width));
m_snowFlakes.push_back(flake);
}
I have tried to base it from this tutorial
http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.phpA friend also told me that when I do sf::VertexArray::append(), the memory places get changed or something. What could be the problem and how will I be able to fix it?
EDIT: I should also mention that i´ve tried to make vertexArray::resize() to a very large number and then it worked. But that is not an option for me because I don't know how many snowflakes there can be :/