Initial commit
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,3 +32,4 @@
|
||||
*.out
|
||||
*.app
|
||||
|
||||
build/
|
||||
|
23
CMakeLists.txt
Normal file
23
CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
include_directories(/usr/include/SFML)
|
||||
include(FetchContent)
|
||||
# FetchContent_Declare(SFML
|
||||
# GIT_REPOSITORY https://github.com/SFML/SFML.git
|
||||
# GIT_TAG 3.0.0
|
||||
# GIT_SHALLOW ON
|
||||
# EXCLUDE_FROM_ALL
|
||||
# SYSTEM)
|
||||
#FetchContent_MakeAvailable(SFML)
|
||||
find_package(SFML 2.5 COMPONENTS system window graphics REQUIRED)
|
||||
project(hello VERSION 1.0)
|
||||
add_executable(hello main.cpp)
|
||||
#target_link_libraries(hello sfml-graphics)
|
||||
target_link_libraries(hello
|
||||
sfml-system
|
||||
sfml-window
|
||||
sfml-graphics
|
||||
sfml-audio
|
||||
)
|
||||
|
9
Makefile
Normal file
9
Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
SHELL := /bin/bash
|
||||
.DEFAULT_GOAL := build
|
||||
.PHONY: build
|
||||
|
||||
build:
|
||||
@if test -d build; then rm -fr build; fi
|
||||
@cmake -B build -S . -DCMAKE_PREFIX_PATH="/usr;/usr/lib64;/usr/lib64/cmake" -DCMAKE_SUPPRESS_DEVELOPER_WARNINGS=ON
|
||||
@cmake --build build
|
||||
@build/hello
|
BIN
cute_image.jpg
Executable file
BIN
cute_image.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
50
main.cpp
Normal file
50
main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
int main() {
|
||||
// Create the main window
|
||||
auto mode = sf::VideoMode({2048, 2048});
|
||||
auto window = sf::RenderWindow(mode, "SFML window");
|
||||
|
||||
// Load a sprite to display
|
||||
sf::Texture texture;
|
||||
if (!texture.loadFromFile("cute_image.jpg")) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sf::Sprite sprite(texture);
|
||||
|
||||
// Create a graphical text to display
|
||||
auto font = sf::Font();
|
||||
font.loadFromFile("arial.tff");
|
||||
sf::Text text("Hello SFML", font, 50); // ✅
|
||||
// Load a music to play
|
||||
sf::Music music;
|
||||
music.openFromFile("nice_music.ogg");
|
||||
|
||||
// Play the music
|
||||
music.play();
|
||||
|
||||
// Start the game loop
|
||||
while (window.isOpen()) {
|
||||
// Process events
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
if (event.type == sf::Event::Closed) {
|
||||
window.close();
|
||||
}
|
||||
|
||||
// Clear screen
|
||||
window.clear();
|
||||
|
||||
// Draw the sprite
|
||||
window.draw(sprite);
|
||||
|
||||
// Draw the string
|
||||
window.draw(text);
|
||||
|
||||
// Update the window
|
||||
window.display();
|
||||
}
|
||||
}
|
||||
}
|
BIN
nice_music.ogg
Normal file
BIN
nice_music.ogg
Normal file
Binary file not shown.
Reference in New Issue
Block a user