first commit sfml template
This commit is contained in:
commit
7657249287
45
.gitignore
vendored
Normal file
45
.gitignore
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
# Build directories
|
||||
build/
|
||||
cmake-build-*/
|
||||
*.exe
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# CMake
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
Makefile
|
||||
*.cmake
|
||||
!CMakeLists.txt
|
||||
|
||||
# VSCodium / VSCode
|
||||
*.code-workspace
|
||||
.vscode/.history
|
||||
|
||||
# OS specific
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Compiler outputs
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.a
|
||||
|
||||
# Debug files
|
||||
*.pdb
|
||||
*.ilk
|
||||
|
||||
# IDE specific
|
||||
.idea/
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.log
|
||||
*.swp
|
||||
*~
|
||||
30
.vscode/c_cpp_properties.json
vendored
Normal file
30
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"C:/msys64/mingw64/include"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "gcc-x64"
|
||||
},
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/usr/include",
|
||||
"/usr/local/include"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/g++",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
47
.vscode/launch.json
vendored
Normal file
47
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug (Windows)",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/bin/StrategyGame.exe",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "CMake: Build"
|
||||
},
|
||||
{
|
||||
"name": "Debug (Linux)",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/bin/StrategyGame",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/usr/bin/gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "CMake: Build"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
.vscode/settings.json
vendored
Normal file
25
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"terminal.integrated.profiles.windows": {
|
||||
"MSYS2 MinGW64": {
|
||||
"path": "C:\\msys64\\usr\\bin\\bash.exe",
|
||||
"args": [
|
||||
"--login",
|
||||
"-i"
|
||||
],
|
||||
"env": {
|
||||
"MSYSTEM": "MINGW64",
|
||||
"CHERE_INVOKING": "1",
|
||||
"MSYS2_PATH_TYPE": "inherit"
|
||||
}
|
||||
},
|
||||
"PowerShell": {
|
||||
"path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
|
||||
"args": ["-NoLogo"]
|
||||
}
|
||||
},
|
||||
"terminal.integrated.defaultProfile.windows": "MSYS2 MinGW64",
|
||||
"files.associations": {
|
||||
"*.hpp": "cpp",
|
||||
"*.cpp": "cpp"
|
||||
}
|
||||
}
|
||||
102
.vscode/tasks.json
vendored
Normal file
102
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "CMake: Configure",
|
||||
"type": "shell",
|
||||
"command": "cmake",
|
||||
"args": [
|
||||
"-B",
|
||||
"build",
|
||||
"-S",
|
||||
".",
|
||||
"-G",
|
||||
"Unix Makefiles"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "CMake: Build",
|
||||
"type": "shell",
|
||||
"command": "cmake",
|
||||
"args": [
|
||||
"--build",
|
||||
"build",
|
||||
"--config",
|
||||
"Debug"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"dependsOn": ["CMake: Configure"],
|
||||
"problemMatcher": ["$gcc"]
|
||||
},
|
||||
{
|
||||
"label": "CMake: Clean",
|
||||
"type": "shell",
|
||||
"command": "cmake",
|
||||
"args": [
|
||||
"--build",
|
||||
"build",
|
||||
"--target",
|
||||
"clean"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Run Game",
|
||||
"type": "shell",
|
||||
"windows": {
|
||||
"command": "${workspaceFolder}/build/bin/StrategyGame.exe"
|
||||
},
|
||||
"linux": {
|
||||
"command": "${workspaceFolder}/build/bin/StrategyGame"
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"dependsOn": ["CMake: Build"],
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Clean Build Directory",
|
||||
"type": "shell",
|
||||
"windows": {
|
||||
"command": "Remove-Item",
|
||||
"args": [
|
||||
"-Path",
|
||||
"build",
|
||||
"-Recurse",
|
||||
"-Force",
|
||||
"-ErrorAction",
|
||||
"SilentlyContinue"
|
||||
]
|
||||
},
|
||||
"linux": {
|
||||
"command": "rm",
|
||||
"args": [
|
||||
"-rf",
|
||||
"build"
|
||||
]
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
58
CMakeLists.txt
Normal file
58
CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(StrategyGame LANGUAGES CXX)
|
||||
|
||||
# C++ Standard
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Build type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
|
||||
# Output directory
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# Find SFML
|
||||
find_package(SFML 3 COMPONENTS Graphics Window System Network REQUIRED)
|
||||
|
||||
# Source files
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
# Create executable
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
# Link SFML
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
SFML::Graphics
|
||||
SFML::Window
|
||||
SFML::System
|
||||
SFML::Network
|
||||
)
|
||||
|
||||
# Windows specific: Copy DLLs to output directory
|
||||
if(WIN32)
|
||||
# Copy SFML DLLs after build
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:SFML::Graphics>
|
||||
$<TARGET_FILE:SFML::Window>
|
||||
$<TARGET_FILE:SFML::System>
|
||||
$<TARGET_FILE:SFML::Network>
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>
|
||||
)
|
||||
endif()
|
||||
|
||||
# Enable more warnings
|
||||
if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
|
||||
else()
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
|
||||
endif()
|
||||
|
||||
# Print build info
|
||||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||
message(STATUS "C++ standard: ${CMAKE_CXX_STANDARD}")
|
||||
message(STATUS "SFML version: ${SFML_VERSION}")
|
||||
208
README.md
Normal file
208
README.md
Normal file
@ -0,0 +1,208 @@
|
||||
# SFML Strategy Game - CMake Setup
|
||||
|
||||
Dieses Projekt nutzt **CMake** für plattformunabhängiges Bauen mit SFML 3.x.
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
### Windows
|
||||
|
||||
1. **MSYS2 installieren**
|
||||
- Download: https://www.msys2.org/
|
||||
- Installiere nach `C:\msys64` (Standard)
|
||||
- Nach Installation: MSYS2 MINGW64 Terminal öffnen
|
||||
|
||||
2. **Pakete installieren**
|
||||
```bash
|
||||
pacman -Syu
|
||||
pacman -S mingw-w64-x86_64-gcc
|
||||
pacman -S mingw-w64-x86_64-sfml
|
||||
pacman -S mingw-w64-x86_64-cmake
|
||||
pacman -S mingw-w64-x86_64-gdb
|
||||
pacman -S make
|
||||
```
|
||||
|
||||
3. **VSCodium / VS Code**
|
||||
- Installiere VSCodium oder VS Code
|
||||
- Installiere Extensions:
|
||||
- `C/C++` (Microsoft)
|
||||
- `CMake Tools` (optional, aber empfohlen)
|
||||
- `cppdbg` (für Debugging)
|
||||
|
||||
### Linux (Ubuntu/Debian)
|
||||
|
||||
1. **Pakete installieren**
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install build-essential
|
||||
sudo apt install cmake
|
||||
sudo apt install libsfml-dev
|
||||
sudo apt install gdb
|
||||
```
|
||||
|
||||
2. **VSCodium / VS Code**
|
||||
- Installiere VSCodium oder VS Code
|
||||
- Installiere Extensions:
|
||||
- `C/C++` (Microsoft)
|
||||
- `CMake Tools` (optional)
|
||||
- `cppdbg` (für Debugging)
|
||||
|
||||
## Projekt Setup
|
||||
|
||||
### Mit VSCodium (empfohlen)
|
||||
|
||||
1. **Projekt öffnen** in VSCodium
|
||||
|
||||
2. **Bauen:**
|
||||
- Drücke `Ctrl+Shift+B` → Wähle "CMake: Build"
|
||||
- Oder einfach `Ctrl+Shift+B` (Standard Build-Task)
|
||||
|
||||
3. **Ausführen:**
|
||||
- `Ctrl+Shift+P` → "Tasks: Run Test Task"
|
||||
- Oder `F5` zum Debuggen
|
||||
|
||||
### Manuell (Terminal)
|
||||
|
||||
**Konfigurieren:**
|
||||
```bash
|
||||
cmake -B build -S .
|
||||
```
|
||||
|
||||
**Bauen:**
|
||||
```bash
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
**Ausführen:**
|
||||
|
||||
Windows (MSYS2):
|
||||
```bash
|
||||
./build/bin/StrategyGame.exe
|
||||
```
|
||||
|
||||
Linux:
|
||||
```bash
|
||||
./build/bin/StrategyGame
|
||||
```
|
||||
|
||||
## Projekt-Struktur
|
||||
|
||||
```
|
||||
projekt/
|
||||
├── CMakeLists.txt # CMake Konfiguration
|
||||
├── .vscode/
|
||||
│ ├── tasks.json # Build-Tasks
|
||||
│ ├── launch.json # Debug-Konfiguration
|
||||
│ ├── c_cpp_properties.json
|
||||
│ └── settings.json # Terminal-Einstellungen
|
||||
├── src/
|
||||
│ └── main.cpp # Haupt-Spielcode
|
||||
├── build/ # Generierter Build-Ordner
|
||||
│ └── bin/ # Kompilierte Executable
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Debugging
|
||||
|
||||
### Breakpoints setzen
|
||||
- Klicke links neben die Zeilennummer (roter Punkt)
|
||||
|
||||
### Debugging starten
|
||||
- `F5` - Start Debugging
|
||||
- `F10` - Step Over
|
||||
- `F11` - Step Into
|
||||
- `Shift+F11` - Step Out
|
||||
- `Shift+F5` - Stop
|
||||
|
||||
## Build-Typen
|
||||
|
||||
**Debug (Standard):**
|
||||
```bash
|
||||
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
**Release (optimiert):**
|
||||
```bash
|
||||
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
## DLL-Verwaltung (Windows)
|
||||
|
||||
CMake kopiert **automatisch** alle benötigten SFML-DLLs in den `build/bin/` Ordner!
|
||||
|
||||
Kein manuelles Kopieren nötig. 🎉
|
||||
|
||||
## Distribution / Release
|
||||
|
||||
### Windows
|
||||
|
||||
**Release bauen:**
|
||||
```bash
|
||||
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --config Release
|
||||
```
|
||||
|
||||
Der `build/bin/` Ordner enthält dann:
|
||||
- `StrategyGame.exe`
|
||||
- Alle benötigten `.dll` Dateien
|
||||
|
||||
→ Diesen Ordner verteilen!
|
||||
|
||||
### Linux
|
||||
|
||||
```bash
|
||||
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
Die Executable ist in `build/bin/StrategyGame`.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Windows: CMake not found
|
||||
```bash
|
||||
# In MSYS2 MINGW64:
|
||||
pacman -S mingw-w64-x86_64-cmake
|
||||
```
|
||||
|
||||
### Linux: SFML not found
|
||||
```bash
|
||||
sudo apt install libsfml-dev
|
||||
```
|
||||
|
||||
### "No such file or directory" beim Build
|
||||
- Stelle sicher, dass du im Projekt-Root-Verzeichnis bist
|
||||
- `CMakeLists.txt` muss im aktuellen Verzeichnis sein
|
||||
|
||||
### Build-Ordner aufräumen
|
||||
```bash
|
||||
rm -rf build
|
||||
cmake -B build -S .
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
## Nützliche CMake-Befehle
|
||||
|
||||
```bash
|
||||
# Neukonfigurieren
|
||||
cmake -B build -S .
|
||||
|
||||
# Bauen (verbose)
|
||||
cmake --build build --verbose
|
||||
|
||||
# Nur bestimmtes Target bauen
|
||||
cmake --build build --target StrategyGame
|
||||
|
||||
# Clean
|
||||
cmake --build build --target clean
|
||||
|
||||
# Kompletter Rebuild
|
||||
rm -rf build && cmake -B build -S . && cmake --build build
|
||||
```
|
||||
|
||||
## Nützliche Links
|
||||
|
||||
- CMake Dokumentation: https://cmake.org/documentation/
|
||||
- SFML Dokumentation: https://www.sfml-dev.org/documentation/3.0.0/
|
||||
- SFML mit CMake: https://www.sfml-dev.org/tutorials/3.0/compile-with-cmake.php
|
||||
30
src/main.cpp
Normal file
30
src/main.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Network.hpp>
|
||||
|
||||
int main() {
|
||||
// Create window with SFML 3.x syntax
|
||||
sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML Game");
|
||||
window.setFramerateLimit(60);
|
||||
|
||||
// Simple green circle for testing
|
||||
sf::CircleShape shape(50.f);
|
||||
shape.setFillColor(sf::Color::Green);
|
||||
shape.setPosition({350.f, 200.f});
|
||||
|
||||
// Main game loop
|
||||
while (window.isOpen()) {
|
||||
// Event handling (SFML 3.x style)
|
||||
while (auto event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Clear, draw, display
|
||||
window.clear(sf::Color::Black);
|
||||
window.draw(shape);
|
||||
window.display();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user