One more question regarding vertexarrays... Is it not possible for us to modify the size as we add more vertices to it?
This is the code I use to add a rectangular sprite (Basically I use this function to replace any draw(Sprite) function in the previous version). Every time I need to add the 'sprite', I increase the size of the vertexarray by 4 and inputted the details (position, texture coordinates). This, however, results in a heap corruption... So, are we supposed to immediately declare how many vertices we need (just like in the tutorial example)? Or is there a way to modify the vertices amount as you draw?
(Vertices is the name of the VertexArray)
(xstr, ystr, xlen and ylen are vectors of float denoting the sprite [id]'s texture rect.)
(Please ignore the whitespace errors)
////Adds a quad at position xpos, ypos with texturerect id
void VertexManager::AddQuad(float xpos, float ypos, int id){
sf::Int8 now = Vertices.getVertexCount();
Vertices.resize( now + 4 );
sf::Vertex* Quad = &Vertices[now];
Quad[0].position = sf::Vector2f ( xpos , ypos );
Quad[1].position = sf::Vector2f ( xpos + xlen[id] , ypos );
Quad[2].position = sf::Vector2f ( xpos + xlen[id] , ypos + ylen[id] );
Quad[3].position = sf::Vector2f ( xpos , ypos + ylen[id] );
Quad[0].texCoords = sf::Vector2f ( xstr[id] ,ystr[id] );
Quad[1].texCoords = sf::Vector2f ( xstr[id]+xlen[id] ,ystr[id] );
Quad[2].texCoords = sf::Vector2f ( xstr[id]+xlen[id] ,ystr[id] + ylen[id] );
Quad[3].texCoords = sf::Vector2f ( xstr[id] ,ystr[id] + ylen[id] );
}
Thanks in advance!