J'aimerais juste dessiner une serie de lignes, Shape est abstraite dans la 2.0 contrairement a la 1.6, donc j'utilise ConvexShape, je voulais savoir si cette classe est bien sensée fonctionner comme prévu dans la 2.0RC, ou s'il n'y a pas une autre solution.
Voici mon code:
#define FOR(a) for(size_t i = 0; i < a; ++i)
struct shape_util
{
sf::ConvexShape Polygon;
//sf::Shape Polygon;
sf::RenderWindow * window;
map<string, sf::Sprite> sprites;
map<string, sf::Texture> textures;
void init()
{
window = new sf::RenderWindow (sf::VideoMode(800, 600), "procedural shape utility");
window->setMouseCursorVisible(false);
textures["cursor"] = sf::Texture();
textures["bg"] = sf::Texture();
sprites["cursor"] = sf::Sprite();
sprites["bg"] = sf::Sprite();
textures["bg"].loadFromFile("grid.png");
textures["cursor"].loadFromFile("cursor.png");
sprites["bg"].setTexture(textures["bg"]);
sprites["cursor"].setTexture(textures["cursor"]);
Polygon.setFillColor(sf::Color(0,200,0, 255));
}
~shape_util() { delete window; }
void handle_loop()
{
while (window->isOpen())
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == sf::Event::Closed)// || event.type==sf::Event::KeyPressed)
window->close();
if(event.type == sf::Event::KeyPressed)// || event.type == sf::Event::KeyReleased)
switch(event.key.code)
{
case Keyboard::Escape:
window->close();
break;
}
if(event.type == sf::Event::MouseMoved)
{
sprites["cursor"].setPosition(event.mouseMove.x, event.mouseMove.y);
window->draw(Polygon);
}
if(event.type == sf::Event::MouseButtonPressed)
{
Polygon.setPointCount(Polygon.getPointCount()+1);
Vector2f v(float(event.mouseMove.x), float(event.mouseMove.y));
Polygon.setPoint(Polygon.getPointCount()-1, v);
//Polygon.set
//window->draw(Polygon);
size_t u = Polygon.getPointCount();
cout << "point begin" << endl;
FOR(u)
cout << " point " << i << ": " <<
Polygon.getPoint(i).x << " " << Polygon.getPoint(i).y << endl;
cout << "point end" << endl;
}
if(event.type == sf::Event::MouseButtonReleased)
{
}
if(event.type == sf::Event::KeyPressed) {}
if(event.type == sf::Event::KeyReleased) {}
window->clear();
window->draw(sprites["bg"]);
window->draw(Polygon);
window->draw(sprites["cursor"]);
window->display();
}
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
shape_util dada;
dada.init();
dada.handle_loop();
}
Mon code compile et charge les fichiers tout bien, je n'arrive pas a voir le polygone dessiné...