From 381ff5882b947b7d3087fa7ace157a159e21b4e2 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 9 Mar 2015 23:40:42 +0100 Subject: [PATCH] Create SFML Window Note: sfml .dlls should be manually copied to build directory. --- src/main.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++--- src/rpg.pro | 16 +++++++++--- src/rpg.pro.user | 4 +-- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5f5419b..402aff2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,68 @@ #include - -using namespace std; +#include 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; } diff --git a/src/rpg.pro b/src/rpg.pro index 4b84c86..3b0c3f5 100644 --- a/src/rpg.pro +++ b/src/rpg.pro @@ -1,10 +1,20 @@ -TEMPLATE = app CONFIG += console +CONFIG += c++11 CONFIG -= app_bundle CONFIG -= qt -SOURCES += main.cpp - include(deployment.pri) 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 + diff --git a/src/rpg.pro.user b/src/rpg.pro.user index 46f20ca..5425e06 100644 --- a/src/rpg.pro.user +++ b/src/rpg.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -226,7 +226,7 @@ rpg - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Rick/Documents/GitHub/rpg/rpg/rpg.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Rick/Documents/GitHub/rpg/src/rpg.pro rpg.pro false