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; +} 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..427fe600 --- /dev/null +++ b/examples/sfml/main.cpp @@ -0,0 +1,16 @@ +#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; +}