bool MapTexture::loadMap(const std::string& tileset){
if (test){// when i want to change my tile map i come here
if (!m_tileset.loadFromFile(tileset)) return false;
m_vertices.clear(); // i even cleard the array to make sure nothing remains
m_vertices.setPrimitiveType(sf::Quads);
unsigned int i,j;
float x = m_map->getSizeMap().x;
float y = m_map->getSizeMap().y;
m_vertices.resize(x*y*4);
for (i = 0; i < x; i++)
for (j = 5; j < y+5; j++)
{
float tx = m_map->getTileSize().x;
float ty = m_map->getTileSize().y;
int t = i+j*x;
int tileValue = 1;
int tCol;
if (tileValue <= 0) continue;
else{
tCol = (tileValue % static_cast<int>(m_tileset.getSize().x/tx)); // calculate position of the texture
//Here i mess things up, it suppose to have a ridiculous look but nothing happens at all
sf::Vertex* quad = &m_vertices[(i + j * x - 5*x) * 4];
quad[0].position = sf::Vector2f(i*tx,j*ty+5*ty);
quad[1].position = sf::Vector2f((i+1)*tx,j*ty+5*ty);
quad[2].position = sf::Vector2f((i+1)*tx,(j+1)*ty+5*ty);
quad[3].position = sf::Vector2f(i*tx,(j+1)*ty+5*ty);
quad[0].texCoords = sf::Vector2f(tCol*tx, 0);
quad[1].texCoords = sf::Vector2f((tCol+1)*tx,0);
quad[2].texCoords = sf::Vector2f((tCol+1)*tx, 40);
quad[3].texCoords = sf::Vector2f(tCol*tx, 40);
}
}
}
else{ // normally i come here
if (!m_tileset.loadFromFile(tileset)) return false;
m_vertices.setPrimitiveType(sf::Quads);
unsigned int i,j;
float x = m_map->getSizeMap().x;
float y = m_map->getSizeMap().y;
m_vertices.resize(x*y*4);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
{
float tx = m_map->getTileSize().x;
float ty = m_map->getTileSize().y;
int t = i+j*x;
int tileValue = m_map->getMap()[t];
int tCol;
if (tileValue <= 0) continue;
else{
tCol = (tileValue % static_cast<int>(m_tileset.getSize().x/tx)); // calculate position of the texture
sf::Vertex* quad = &m_vertices[(i + j * x) * 4];
quad[0].position = sf::Vector2f(i*tx,j*ty);
quad[1].position = sf::Vector2f((i+1)*tx,j*ty);
quad[2].position = sf::Vector2f((i+1)*tx,(j+1)*ty);
quad[3].position = sf::Vector2f(i*tx,(j+1)*ty);
quad[0].texCoords = sf::Vector2f(tCol*tx, 0);
quad[1].texCoords = sf::Vector2f((tCol+1)*tx,0);
quad[2].texCoords = sf::Vector2f((tCol+1)*tx, 40);
quad[3].texCoords = sf::Vector2f(tCol*tx, 40);
}
}
}
return true;
};
as you can see, when test = true, the test code is executed and actually it did executed, but the nothing changed in my view, i even tried to make some wrong code to make a clearly difference result but nothing happens at all, i have to suppose that when the vertex array is loaded into memory, the gpu cached it somewhere for later use and doesnt refer to the new one anymore, sounds stupid but i have no idea otherwise