add SFML fullscreen example

This commit is contained in:
Alexander Popov 2024-02-24 19:29:12 +03:00
parent 6f497d3e7c
commit c7516d542c
4 changed files with 71 additions and 2 deletions

View File

@ -28,12 +28,12 @@ indent_size = 2
# C # C
[{*.c,*.h}] [{*.c,*.h}]
indent_style = space indent_style = space
indent_size = 4 indent_size = 2
# C++ # C++
[{*.cpp,*.ino,*.hpp}] [{*.cpp,*.ino,*.hpp}]
indent_style = space indent_style = space
indent_size = 4 indent_size = 2
# V # V
[{*.v,v.mod}] [{*.v,v.mod}]

3
projects/SFML/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# XMake
build/
.xmake/

View File

@ -0,0 +1,58 @@
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Text.hpp>
int main() {
bool isFullscreen = false;
int screenWidth = sf::VideoMode::getDesktopMode().width;
int screenHeight = sf::VideoMode::getDesktopMode().height;
sf::Font font;
std::string fontPath = "/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf";
if (!font.loadFromFile(fontPath)) {
std::cout << "Error loading font: " << fontPath << std::endl;
exit(EXIT_FAILURE);
}
sf::Text text;
text.setFont(font);
text.setCharacterSize(24);
text.setFillColor(sf::Color::White);
text.setString("Press F keyboard button to toggle fullscreen mode");
sf::RenderWindow window;
window.create(sf::VideoMode(640, 480), "Fullscreen example");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::F)) {
isFullscreen = !isFullscreen;
window.close();
if (isFullscreen)
window.create(sf::VideoMode(screenWidth, screenHeight),
"Fullscreen example", sf::Style::Fullscreen);
else
window.create(sf::VideoMode(640, 480), "Fullscreen example",
sf::Style::Default);
}
}
window.clear(sf::Color::Black);
window.draw(text);
window.display();
}
return EXIT_SUCCESS;
}

8
projects/SFML/xmake.lua Normal file
View File

@ -0,0 +1,8 @@
set_project("sfml_examples")
set_languages("cxx14")
target("fullscreen")
set_kind("binary")
add_syslinks("sfml-graphics", "sfml-window", "sfml-system")
add_files("fullscreen.cpp")
-- add_deps("log", "trt_api", "yolov8", "serial")