Last active
April 15, 2018 09:35
-
-
Save vfjpl/bd442e34036547e4ccb05200762fa274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <iostream> | |
int main() | |
{ | |
// Create the main window | |
sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window"); | |
// Load a sprite to display | |
sf::Texture texture; | |
if (!texture.loadFromFile("cb.bmp")) | |
return EXIT_FAILURE; | |
sf::Sprite sprite(texture); | |
//for every test uncomment only one line | |
//one line one test | |
//sprite.setPosition( sprite.getGlobalBounds().width/2, sprite.getGlobalBounds().height/2 );//fully visible | |
//sprite.setPosition( -app.getSize().x, -app.getSize().y );//fully invisible | |
//sprite.setPosition( -sprite.getGlobalBounds().width/2, -sprite.getGlobalBounds().height/2 );//partially visible | |
sf::Uint16 frame = 0; | |
float frame_time = 0; | |
sf::Time time; | |
sf::Clock clock; | |
// Start the game loop | |
while (app.isOpen()) | |
{ | |
// Process events | |
sf::Event event; | |
while (app.pollEvent(event)) | |
{ | |
// Close window : exit | |
if (event.type == sf::Event::Closed) | |
app.close(); | |
} | |
// Clear screen | |
app.clear(); | |
// Draw the sprite | |
//if fps is to high increase number of drew sprites | |
for(int i=0; i<100; i++) | |
app.draw(sprite); | |
// Update the window | |
app.display(); | |
time = clock.restart(); | |
frame_time +=time.asSeconds(); | |
frame++; | |
std::cout<<"current = "<<1/time.asSeconds()<<" average = "<<frame/frame_time<<"\n"; | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment