That's great! Thank you, Paul, but I'm not sure how would I create this offset in the height axle...
The code for tilemap I have currently is:
// populate the vertex array, with one quad per tile
for (unsigned int i = 0; i < width; ++i)
for (unsigned int j = 0; j < height; ++j)
{
// get the current tile number
int tileNumber = tiles[i + j * width];
// find its position in the tileset texture
int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);
// get a pointer to the current tile's quad
sf::Vertex* quad = &m_vertices[(i + j * width) * 4];
// define its 4 corners
quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
// define its 4 texture coordinates
quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
}
I don't know what the rest of the code looks like, if there is any structure for each tile. Anyway while you are generating x and y positions during for loop, the heights for all tiles must be stored somewhere. For example in std::vector<int> m_heightmap[width * height - 1].
Then just add height to all y axis:
quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y + m_heightmap[this_tile_index]);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y + m_heightmap[this_tile_index + 1]);
quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y + m_heightmap[this_tile_index + 1 + row_bellow]);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y + m_heightmap[index_of_tile_row_bellow]);
You must be carefull about index, it will be different in each line because quads have separated coordinates and you're counting with neighboring tiles which follow the changed height. It is probably not the best described, but the logic behind is straightforward.