Add SDL to CMake
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user