Hello, im trying learn vertex arrays and i wrrote very similiar class to title map in 2.1sfml tut.
But when i run the program there are just triangles and other suff which shouldnt be there...
Actually the ounly difference between my class and class from tutorial is that im using just one FOR cycle - the variables to place vertices are derived from it(in tut there are two cycles)
class MAPA : public sf::Drawable, public sf::Transformable
{
public:
bool nacteni(const std::string& nazev_obrazku, sf::Vector2u velikost_dlazdice, const int* pole, unsigned int pocet_poli_sirka, unsigned int pocet_poli_vyska)
{
if (!textura.loadFromFile(nazev_obrazku))
return false;
vrcholy.setPrimitiveType(sf::Quads);
vrcholy.resize(pocet_poli_sirka * pocet_poli_vyska * 4);
int b = 0,c = 0; //this is for position of quad
for (unsigned int a = 0; a < pocet_poli_sirka * pocet_poli_vyska; ++a){
int cislo_dlazdice = pole[a];
sf::Vertex* finalni = &vrcholy[a];
if(b == pocet_poli_sirka){b = 0;c ++;}
finalni[0].position = sf::Vector2f(b * velikost_dlazdice.x, c * velikost_dlazdice.y);
finalni[1].position = sf::Vector2f((b + 1) * velikost_dlazdice.x, c * velikost_dlazdice.y);
finalni[2].position = sf::Vector2f((b + 1) * velikost_dlazdice.x, (c + 1) * velikost_dlazdice.y);
finalni[3].position = sf::Vector2f(b * velikost_dlazdice.x, (c + 1) * velikost_dlazdice.y);
int e, d;
if (cislo_dlazdice == 0){e = 22;d = 30;}
else if (cislo_dlazdice == 1){e = 228;d = 30;}
else if (cislo_dlazdice == 2){e = 10;d = 132;}
else if (cislo_dlazdice == 3){e = 216;d = 132;}
else std::cout<<"imposible";
finalni[0].texCoords = sf::Vector2f(e,d);
finalni[1].texCoords = sf::Vector2f(e + 10 ,d);
finalni[2].texCoords = sf::Vector2f(e + 10,d + 10);
finalni[3].texCoords = sf::Vector2f(e ,d + 10);
b ++;
}
return true;
}
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
states.texture = &textura;
target.draw(vrcholy, states);
}
sf::VertexArray vrcholy;
sf::Texture textura;
};
Im sorry for names of variables, but the original code is realy similiar The setting texture to vertex is just done little bit easier(in my opinion).
Thank you