Difference between revisions of "C++ Drawing to the screen"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Drawing a Line)
Line 11: Line 11:
  
 
SFML has 5 different components, so click each one and click install.
 
SFML has 5 different components, so click each one and click install.
 +
 +
==Creating A Window==
 +
The code below will create a window, and also provides a loop to keep the window open and to check for window events:
 +
 +
<syntaxhighlight lang=c++>
 +
#include <SFML/Graphics.hpp>
 +
 +
int main()
 +
{
 +
sf::RenderWindow window{{ 800, 800 }, "Window Title"};
 +
window.setFramerateLimit(60);
 +
 +
while (window.isOpen())
 +
{
 +
sf::Event event;
 +
while (window.pollEvent(event))
 +
{
 +
if (event.type == sf:: Event::Closed)
 +
{
 +
window.close();
 +
}
 +
}
 +
window.clear();
 +
window.display();
 +
}
 +
}

Revision as of 13:26, 13 June 2019

SFML

This method will require you to install some packages. In Visual Studio, and Project, select 'Manage Nuget Packages'.

Click the browse tab and type:

'sfml'

Now look for the version numbers, each version has a slightly different name. I have found:

Sfml.png

SFML has 5 different components, so click each one and click install.

Creating A Window

The code below will create a window, and also provides a loop to keep the window open and to check for window events:

<syntaxhighlight lang=c++>

  1. include <SFML/Graphics.hpp>

int main() { sf::RenderWindow window{{ 800, 800 }, "Window Title"}; window.setFramerateLimit(60);

while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf:: Event::Closed) { window.close(); } } window.clear(); window.display(); } }