1
Graphics / Quad (2.6) to Triangle/TriangleStrip (3.0)
« on: September 06, 2025, 02:08:14 am »
Hi, I'm porting my project to SFML3.0 and I'm having trouble converting the Quads to Triangle or TriangleStrip, this is part of the code:
This was working correctly in 2.6 (this is tmxLoader by fallahn) but this is the only issue I have. m_patches is storing a lot of quads so it's not enough to convert just one quad, I have to convert the whole m_patches which contains lots of quads.
What this code draws now is a messed up map with triangles all over the place.
Also I don't get if it's better to convert it to just Triangles or TriangleStrips? Sorry, lots of questions. Any idea will help.
Code: [Select]
if(!m_visible) return;
std::vector<sf::Vertex> triangles;
for (int i = 0; i < 6; i++) triangles.push_back(sf::Vertex());
for(auto x = m_visiblePatchStart.x; x <= m_visiblePatchEnd.x; ++x)
{
for(auto y = m_visiblePatchStart.y; y <= m_visiblePatchEnd.y; ++y)
{
auto index = y * m_patchCount.x + x;
if(index < m_patches.size() && !m_patches[index].empty())
{
states.texture = &m_texture;
// convert Quad to 2 Triangles
/*
0 -- 1 0 -- 1
| | becomes | / |
| | | / |
3 -- 2 3 -- 2
*/
triangles[0] = m_patches[index][3];
triangles[1] = m_patches[index][0];
triangles[2] = m_patches[index][2];
triangles[3] = m_patches[index][1];
triangles[4] = m_patches[index][7];
triangles[5] = m_patches[index][4];
rt.draw(triangles.data(), static_cast<unsigned>(m_patches[index].size()), sf::PrimitiveType::TriangleStrip, states);
//rt.draw(m_patches[index].data(), static_cast<unsigned>(m_patches[index].size()), sf::PrimitiveType::Quads, states);
}
}
}This was working correctly in 2.6 (this is tmxLoader by fallahn) but this is the only issue I have. m_patches is storing a lot of quads so it's not enough to convert just one quad, I have to convert the whole m_patches which contains lots of quads.
What this code draws now is a messed up map with triangles all over the place.
Also I don't get if it's better to convert it to just Triangles or TriangleStrips? Sorry, lots of questions. Any idea will help.

