Advertisement
Felanpro

SFML Window Tutorial

Mar 17th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <SFML/Window.hpp>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     sf::Window window(sf::VideoMode(800, 600), "Generic name for a window");
  11.     //First argument video mode determines the size of the window. In this case 800 pixels wide and 600 pixels long.
  12.     //Second argument determines the name for the window.
  13.     //sf in this case is just a namespace like std and can be erased from having to type out
  14.     //by writing in in the beginning of the code "using namespace sf".
  15.  
  16.     /* Alternative way to creating a window
  17.     sf::Window second_window;
  18.     second_window.create(sf::VideoMode(400, 100), "The second window");
  19.     */
  20.     int x = 0;
  21.     int y;
  22.  
  23.     window.setVerticalSyncEnabled(true); //Synchronize the refresh rate with the vertical frequency of the monitor.
  24.  
  25.     for (y = 0; y < 4; y++, x += 100)
  26.     {
  27.         window.setPosition(sf::Vector2i(x, 40));
  28.         Sleep(1000);
  29.     }
  30.  
  31.     Sleep(1000);
  32.     window.setSize(sf::Vector2u(400, 400));
  33.  
  34.     Sleep(1000);
  35.     window.setTitle("The name of the window just changed");
  36.  
  37.     // run the program as long as the window is open
  38.     while (window.isOpen())
  39.     {
  40.         // check all the window's events that were triggered since the last iteration of the loop
  41.         sf::Event event;
  42.         while (window.pollEvent(event))
  43.         {
  44.             // "close requested" event: we close the window
  45.             if (event.type == sf::Event::Closed)
  46.                 window.close();
  47.         }
  48.     }
  49.     //The above code will open a window, and terminate when the user closes it.
  50.  
  51.     int pause;
  52.     cin >> pause; //Pause the program
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement