Commit bdd32d7d authored by Geequette's avatar Geequette

Add tutorial part 3

parent 7756573e
......@@ -24,7 +24,6 @@ int main()
"SFML part 3",
sf::Style::Fullscreen);
//sf::RenderWindow window(sf::VideoMode( 800,600),"SFML part 3");
// Enable vertical sync. (vsync)
window.setVerticalSyncEnabled (true);
......@@ -34,7 +33,7 @@ int main()
// Create texture from PNG file
sf::Texture texture;
if (!texture.loadFromFile("../../img/sfml-icon-small.jpg"))
if (!texture.loadFromFile("../../img/sfml-icon-small.png"))
{
std::cerr << "Error while loading texture" << std::endl;
return -1;
......@@ -51,33 +50,17 @@ int main()
sf::Sprite sprite;
sprite.setTexture(texture);
sf::FloatRect spriteSize=sprite.getGlobalBounds();
// sprite.setOrigin(spriteSize.width/2.,spriteSize.height/2.);
std::cout << desktopMode.width << " " << spriteSize.width;
sprite.setOrigin(spriteSize.width/2.,spriteSize.height/2.);
sf::Sprite sprite2=sprite;
sf::Sprite sprite3=sprite;
sf::Sprite sprite4=sprite;
sf::Vertex line[] =
{
sf::Vertex(sf::Vector2f(1366/2, 0)),
sf::Vertex(sf::Vector2f(1366/2, 768))
};
// définit un cercle de rayon 200
sf::CircleShape circle(10);
circle.setOrigin(10,10);
// _________________
// ::: Main loop :::
int x=0;
sf::Clock timer;
while (window.isOpen())
{
// Display fps
// std::cout << 1/timer.restart().asSeconds() << " fps" << std::endl;
std::cout << int(1./timer.restart().asSeconds()) << " fps" << std::endl;
// Process events
sf::Event event;
......@@ -90,39 +73,14 @@ int main()
// Clear the window and apply grey background
window.clear( sf::Color(127,127,127));
// Draw the sprite
// sprite.setPosition(window.getSize().x/2.-spriteSize.width/2., window.getSize().y/2.-spriteSize.height/2.);
// sprite.setPosition(window.getSize().x/2.-spriteSize.width/2., 0);
// sprite.setPosition(0, 128);
// window.draw(sprite);
/*sprite2.setPosition(256, 128);
window.draw(sprite2);
sprite3.setPosition(512, 128);
window.draw(sprite3);
sprite4.setPosition(555, 128);
window.draw(sprite4);
*/
window.draw(line, 2, sf::Lines);
// circle.setPosition((x++%14)*100,0);
// window.draw(circle);
// Draw the sprite in the middle of the screen
sprite.setPosition(window.getSize().x/2., window.getSize().y/2.);
window.draw(sprite);
// Update display and wait for vsync
window.display();
// if (x==1366) window.close();
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment