window
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
build/
|
||||||
|
.cache/
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
project(SFML_game_engine)
|
||||||
|
|
||||||
|
include_directories(include)
|
||||||
|
|
||||||
|
set(SOURCES
|
||||||
|
src/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(SFML
|
||||||
|
GIT_REPOSITORY https://github.com/SFML/SFML.git
|
||||||
|
GIT_TAG 3.0.2
|
||||||
|
GIT_SHALLOW ON
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
SYSTEM)
|
||||||
|
FetchContent_MakeAvailable(SFML)
|
||||||
|
|
||||||
|
add_executable(SFML_game_engine ${SOURCES})
|
||||||
|
|
||||||
|
# target_link_libraries(SFML_game_engine PRIVATE SFML::Graphics)
|
||||||
|
# target_include_directories(SFML_game_engine PRIVATE include)
|
||||||
|
target_link_libraries(SFML_game_engine
|
||||||
|
PRIVATE
|
||||||
|
SFML::Graphics
|
||||||
|
SFML::Window
|
||||||
|
SFML::System
|
||||||
|
)
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// sf::RenderWindow window(sf::VideoMode({600, 400}), "SFML window");
|
||||||
|
sf::RenderWindow window(sf::VideoMode({600, 400}), "SFML window");
|
||||||
|
// window.setVerticalSyncEnabled(true);
|
||||||
|
window.setFramerateLimit(60);
|
||||||
|
|
||||||
|
|
||||||
|
// Load a sprite to display
|
||||||
|
// const sf::Texture texture("original.jpeg");
|
||||||
|
// sf::Sprite sprite(texture);
|
||||||
|
|
||||||
|
// Create a graphical text to display
|
||||||
|
// const sf::Font font("MapleMono-Regular.ttf");
|
||||||
|
// sf::Text text(font, "Hello SFML", 50);
|
||||||
|
|
||||||
|
// Load a music to play
|
||||||
|
sf::RectangleShape player({40, 40});
|
||||||
|
player.setFillColor(sf::Color::Black);
|
||||||
|
player.setOutlineThickness(2);
|
||||||
|
player.setOutlineColor(sf::Color::White);
|
||||||
|
player.setPosition({40, 40});
|
||||||
|
|
||||||
|
// Start the game loop
|
||||||
|
while (window.isOpen()) {
|
||||||
|
// Process events
|
||||||
|
while (const std::optional event = window.pollEvent())
|
||||||
|
{
|
||||||
|
// Close window: exit
|
||||||
|
if (event->is<sf::Event::Closed>())
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear screen
|
||||||
|
// window.clear();
|
||||||
|
|
||||||
|
// Draw the sprite
|
||||||
|
window.clear(sf::Color::Black);
|
||||||
|
window.draw(player);
|
||||||
|
window.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user