forked from Raysh454/SnakeGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
40 lines (29 loc) · 1.02 KB
/
init.c
File metadata and controls
40 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void initSDL(void){
int rendererFlags, windowFlags;
rendererFlags = SDL_RENDERER_ACCELERATED;
windowFlags = 0;
if (SDL_Init(SDL_INIT_VIDEO) < 0){
printf("Failed to initialize SDL: %s\n", SDL_GetError());
exit(1);
}
app.window = SDL_CreateWindow("Snake Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, windowFlags);
if (!app.window){
printf("Failed to create %dx%d window: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
exit(1);
}
SDL_Surface *iconSurface = IMG_Load("images/icon.png");
if (iconSurface == NULL) {
printf("Error loading icon\n");
}
SDL_SetWindowIcon(app.window, iconSurface);
SDL_FreeSurface(iconSurface);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
app.renderer = SDL_CreateRenderer(app.window, -1, rendererFlags);
if (!app.renderer){
printf("Failed to create renderer: %s\n", SDL_GetError());
exit(1);
}
if(!IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)) {
printf("Failed to intialize IMG_Init: %s", SDL_GetError());
}
}