From 20724dd7af86592aef693e63ab1a6aa28e5ca19f Mon Sep 17 00:00:00 2001 From: Yohann Date: Tue, 28 Sep 2021 14:20:03 +0200 Subject: [PATCH 1/3] add sfml example --- examples/sfml/CMakeLists.txt | 14 ++++++++++++++ examples/sfml/main.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/sfml/CMakeLists.txt create mode 100644 examples/sfml/main.cpp diff --git a/examples/sfml/CMakeLists.txt b/examples/sfml/CMakeLists.txt new file mode 100644 index 00000000..d195d61e --- /dev/null +++ b/examples/sfml/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(CPMSFMLExample) + +# ---- Dependencies ---- + +include(../../cmake/CPM.cmake) +CPMAddPackage("gh:SFML/SFML#2.5.1") + +# ---- Executable ---- + +add_executable(CPMSFMLExample main.cpp) +target_compile_features(CPMSFMLExample PRIVATE cxx_std_17) +target_link_libraries(CPMSFMLExample sfml-system sfml-graphics sfml-window sfml-audio) diff --git a/examples/sfml/main.cpp b/examples/sfml/main.cpp new file mode 100644 index 00000000..74439f75 --- /dev/null +++ b/examples/sfml/main.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main() +{ + sf::RenderWindow win(sf::VideoMode(800, 600), "SFML window"); + + while (win.isOpen()) { + sf::Event event; + while (win.pollEvent(event)) { + if (event.type == sf::Event::Closed) win.close(); + } + win.clear(sf::Color::Black); + win.display(); + } + return 0; +} From 742c811d0379851448cf306280496d1bafc2bc55 Mon Sep 17 00:00:00 2001 From: Yohann Date: Tue, 28 Sep 2021 14:31:58 +0200 Subject: [PATCH 2/3] add sdl example --- examples/sdl2/CMakeLists.txt | 14 ++++++++++++++ examples/sdl2/main.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 examples/sdl2/CMakeLists.txt create mode 100644 examples/sdl2/main.cpp diff --git a/examples/sdl2/CMakeLists.txt b/examples/sdl2/CMakeLists.txt new file mode 100644 index 00000000..e6e51d00 --- /dev/null +++ b/examples/sdl2/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(CPMSDLExample) + +# ---- Dependencies ---- + +include(../../cmake/CPM.cmake) +CPMAddPackage("gh:libsdl-org/SDL#release-2.0.16") + +# ---- Executable ---- + +add_executable(CPMSDLExample main.cpp) + +target_link_libraries(CPMSDLExample SDL2) diff --git a/examples/sdl2/main.cpp b/examples/sdl2/main.cpp new file mode 100644 index 00000000..3975cce3 --- /dev/null +++ b/examples/sdl2/main.cpp @@ -0,0 +1,33 @@ +// adapted from : https://gist.github.com/fschr/92958222e35a823e738bb181fe045274 + +#include + +#include + +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 + +int main() { + SDL_Window* window = NULL; + SDL_Surface* screenSurface = NULL; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + std::cerr << "Could not initialize SDL2" << SDL_GetError() << std::endl; + return 1; + } + window = SDL_CreateWindow("hello_sdl2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + if (window == NULL) { + std::cerr << "Could not create window" << SDL_GetError() << std::endl; + return 1; + } + + screenSurface = SDL_GetWindowSurface(window); + SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF)); + SDL_UpdateWindowSurface(window); + SDL_Delay(2000); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} From 28cb735d2d1036d6d91e92470de8a1eb42970048 Mon Sep 17 00:00:00 2001 From: Yohann Date: Sun, 3 Oct 2021 20:59:09 +0200 Subject: [PATCH 3/3] format code --- examples/sfml/main.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/sfml/main.cpp b/examples/sfml/main.cpp index 74439f75..427fe600 100644 --- a/examples/sfml/main.cpp +++ b/examples/sfml/main.cpp @@ -1,17 +1,16 @@ #include #include -int main() -{ - sf::RenderWindow win(sf::VideoMode(800, 600), "SFML window"); +int main() { + sf::RenderWindow win(sf::VideoMode(800, 600), "SFML window"); - while (win.isOpen()) { - sf::Event event; - while (win.pollEvent(event)) { - if (event.type == sf::Event::Closed) win.close(); - } - win.clear(sf::Color::Black); - win.display(); + while (win.isOpen()) { + sf::Event event; + while (win.pollEvent(event)) { + if (event.type == sf::Event::Closed) win.close(); } - return 0; + win.clear(sf::Color::Black); + win.display(); + } + return 0; }