add SFML fullscreen example
This commit is contained in:
parent
6f497d3e7c
commit
c7516d542c
@ -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
3
projects/SFML/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# XMake
|
||||||
|
build/
|
||||||
|
.xmake/
|
58
projects/SFML/fullscreen.cpp
Normal file
58
projects/SFML/fullscreen.cpp
Normal 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
8
projects/SFML/xmake.lua
Normal 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")
|
Loading…
Reference in New Issue
Block a user