Add SDL to CMake

refactor
PgSocks 2 years ago
parent 60673a5283
commit 2b0b5e7b4f

@ -33,3 +33,15 @@ add_executable(robomastersh
target_link_libraries(robomastersh target_link_libraries(robomastersh
robomaster robomaster
) )
find_package(SDL2)
if(SDL2_FOUND)
add_executable(robomasterapp
src/sdl.c
)
target_link_libraries(robomasterapp
robomaster
SDL2::SDL2
)
endif()

@ -0,0 +1,39 @@
#include "robomaster.h"
#include "SDL2/SDL.h"
#include <stdio.h>
#include <stdlib.h>
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;
}
Loading…
Cancel
Save