SFML C++
Introduction
Library download
You can download SFML2 from the website sfml-dev.org
Creating a project
After that, in Visual Studio create an empty C++ project. A console application for win32, for example. And in this project create a file main.cpp
C/C++ General
In
C/C++ → General → Additional Include Directories
Add the path to the include directory
C:\Development\SFML2\include
Linker General
In
Linker → General → Additional Library Directories
Add the path to the lib directory
C:\Development\SFML2\lib
Linker Input
In
Linker → Input → Additional Dependencies
Add these libraries
sfml-audio-d.lib sfml-graphics-d.lib sfml-network-d.lib sfml-system-d.lib sfml-window-d.lib
From the directory
C:\Development\SFML2\bin
Copy these .dll files into the project directory, so they sit next to main.cpp
- sfml-graphics-d-2.dll
- sfml-window-d-2.dll
- sfml-system-d-2.dll
Drawing a circle
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200,200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
The code on this page was not run: it needs the SFML headers and a display, neither of which this environment has.
Article author: Andrei Olegovich