From 2b0b5e7b4f2d1eed20f2f8fff50ed085858142c3 Mon Sep 17 00:00:00 2001 From: PgSocks Date: Mon, 2 Jan 2023 15:57:31 -0600 Subject: [PATCH] Add SDL to CMake --- CMakeLists.txt | 12 ++++++++++++ src/sdl.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/sdl.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 4186383..83d80e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,3 +33,15 @@ add_executable(robomastersh target_link_libraries(robomastersh robomaster ) + +find_package(SDL2) + +if(SDL2_FOUND) + add_executable(robomasterapp + src/sdl.c + ) + target_link_libraries(robomasterapp + robomaster + SDL2::SDL2 + ) +endif() diff --git a/src/sdl.c b/src/sdl.c new file mode 100644 index 0000000..2ffe995 --- /dev/null +++ b/src/sdl.c @@ -0,0 +1,39 @@ +#include "robomaster.h" +#include "SDL2/SDL.h" + +#include +#include + +int main(int argc, char* argv[]) { + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) { + fprintf(stderr, "%s", SDL_GetError()); + return 1; + } + SDL_Window* win = SDL_CreateWindow( + "Robomaster", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 800, 300, + SDL_WINDOW_RESIZABLE ); + if(!win) { + fprintf(stderr, "%s", SDL_GetError()); + return 1; + } + + bool quit = false; + while(!quit) { + SDL_Event event; + while(SDL_PollEvent(&event)) { + switch(event.type) { + case SDL_WINDOWEVENT: + if(event.window.event != SDL_WINDOWEVENT_CLOSE) break; + case SDL_QUIT: + quit = true; + } + } + } + + SDL_Quit(); + return 0; +} +