// SDL2 Hello, World! // This should display a white screen for 2 seconds // compile with: clang++ main.cpp -o hello_sdl2 -lSDL2 // run with: ./hello_sdl2 #include #include #include #define SCREEN_WIDTH 1600 #define SCREEN_HEIGHT 800 int x[16*8]; int y[16*8]; int i=0; int length=1; int delta_x = 1; int delta_y = 0; quit =false; Uint32 updateSnake(Uint32 interval, void* param){ printf("hello\n"); return 0; //' int current_x = x[i]; //' int current_y = y[i]; //' //' } SDL_Window* initSDL(){ SDL_Window* window = NULL; SDL_Surface* screenSurface = NULL; if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError()); exit(1); } window = SDL_CreateWindow( "hello_sdl2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); if (window == NULL) { fprintf(stderr, "could not create window: %s\n", SDL_GetError()); exit(1); } screenSurface = SDL_GetWindowSurface(window); SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0x40, 0x40, 0x40)); SDL_UpdateWindowSurface(window); return window; } void killSDL(SDL_Window* window){ SDL_DestroyWindow(window); SDL_Quit(); } int main(int argc, char* args[]) { SDL_Window* win = initSDL(); //set x and y list to zero memset(x,0,sizeof(int)*16*8); memset(y,0,sizeof(int)*16*8); SDL_TimerID timerId = SDL_AddTimer(500, updateSnake, ""); while(!quit){ SDL_Event event; while(SDL_PollEvent(&event)){ switch(event.type){ case(SDL_QUIT): quit = true; break; } } } killSDL(win); }