0% found this document useful (0 votes)
27 views

#Include #Include : "Exemplosfml"

This C++ code uses the SFML library to create a basic graphical window application. It initializes a render window and loads a background texture and font. The main loop detects window close events, draws the background sprite each frame, and displays the window contents, running at 60 frames per second. This provides a simple template for building a graphical SFML application.

Uploaded by

ion2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

#Include #Include : "Exemplosfml"

This C++ code uses the SFML library to create a basic graphical window application. It initializes a render window and loads a background texture and font. The main loop detects window close events, draws the background sprite each frame, and displays the window contents, running at 60 frames per second. This provides a simple template for building a graphical SFML application.

Uploaded by

ion2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1: #include <iostream>

2: #include <SFML/Graphics.hpp>
3:
4: int main()
5: {
6: sf::ContextSettings settings;
7: settings.antialiasingLevel = 8;
8: //sf::RenderWindow window(sf::VideoMode::getFullscreenModes()[0],
9: sf::RenderWindow window(sf::VideoMode(800,800), "ExemploSFML", sf::S
10: window.setKeyRepeatEnabled(false);
11:
12: sf::Font font;
13: font.loadFromFile("Bold.ttf");
14:
15:
16: sf::Texture background;
17: background.loadFromFile("background.png");
18: background.setSmooth(true);
19:
20: sf::Clock clock;
21: sf::Time time;
22:
23: // This "while" loop goes round and round- perhaps forever
24: while (window.isOpen())
25: {
26: time = sf::seconds(0);
27: // The next 6 lines of code detect if the window is closed
28: // And then shuts down the program
29: sf::Event event;
30: while (window.pollEvent(event))
31: {
32: if (event.type == sf::Event::Closed)
33: // Someone closed the window- bye
34: window.close();
35: }
36:
37: time = clock.getElapsedTime();
38: if(time > sf::seconds(1.0f/60))
39: {
40: clock.restart();
41:
42: window.setView(window.getDefaultView());
43:
44: sf::Sprite sprite;
45: sprite.setTexture(background);
46: sprite.setOrigin(100,100);
47: window.draw(sprite);
48:
49: window.display();
50: }
51: }
52:
53: return 0;
54: }

You might also like