Browse Source

Create SFML Window

Note: sfml .dlls should be manually copied to build directory.
master
Riyyi 10 years ago
parent
commit
381ff5882b
  1. 64
      src/main.cpp
  2. 16
      src/rpg.pro
  3. 4
      src/rpg.pro.user

64
src/main.cpp

@ -1,10 +1,68 @@
#include <iostream> #include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
int main() int main()
{ {
cout << "Hello World!" << endl; std::cout << "Hello World!" << std::endl;
std::string gameName = "rpg";
unsigned int windowStyle = sf::Style::Titlebar | sf::Style::Close;
sf::ContextSettings settings;
settings.antialiasingLevel = 16;
sf::RenderWindow window(sf::VideoMode(1280, 720), gameName, windowStyle, settings);
window.setVerticalSyncEnabled(true);
sf::Clock fpsTimer;
sf::Clock timer;
sf::Time timeElapsed;
// Run the program as long as the window is open
while (window.isOpen())
{
// Check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
// Enter fullscreen mode : key combination : Alt+Enter
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Return) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) {
if (windowStyle == sf::Style::Fullscreen) {
windowStyle = sf::Style::Titlebar | sf::Style::Close;
}
else {
windowStyle = sf::Style::Fullscreen;
}
window.create(sf::VideoMode(1280, 720), gameName, windowStyle, settings);
window.setVerticalSyncEnabled(true);
}
}
}
}
window.clear(sf::Color(0, 0, 0));
window.display();
timeElapsed = timer.getElapsedTime();
if (timeElapsed.asSeconds() > 1)
{
// Display current FPS in window title
timeElapsed = fpsTimer.getElapsedTime();
int fps = 1000000 / timeElapsed.asMicroseconds();
window.setTitle(gameName + " - fps: " + std::to_string(fps));
timer.restart();
}
fpsTimer.restart();
}
return 0; return 0;
} }

16
src/rpg.pro

@ -1,10 +1,20 @@
TEMPLATE = app
CONFIG += console CONFIG += console
CONFIG += c++11
CONFIG -= app_bundle CONFIG -= app_bundle
CONFIG -= qt CONFIG -= qt
SOURCES += main.cpp
include(deployment.pri) include(deployment.pri)
qtcAddDeployment() qtcAddDeployment()
LIBS += -LC:/SFML/lib
CONFIG(release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system
CONFIG(debug, debug|release): LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
INCLUDEPATH += C:/SFML/include
DEPENDPATH += C:/SFML/include
TEMPLATE = app
SOURCES += main.cpp

4
src/rpg.pro.user

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.3.0, 2015-03-09T22:22:28. --> <!-- Written by QtCreator 3.3.0, 2015-03-09T23:11:56. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -226,7 +226,7 @@
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">rpg</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">rpg</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Rick/Documents/GitHub/rpg/rpg/rpg.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Rick/Documents/GitHub/rpg/src/rpg.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">rpg.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">rpg.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>

Loading…
Cancel
Save