summaryrefslogtreecommitdiff
path: root/initialize.c
blob: 75d9e2d95f23829da46bbdef8c12dfdacfb0b82d (plain)
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
#include<stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_image.h>
#include "./constants.h"
#include "./structs.h"

int initialize_window(App* app) {
	if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
		fprintf(stderr, "Error initializing SDL.\n");
		return FALSE;
	}
	app->window = SDL_CreateWindow(
		GAME_TITLE,
		SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED,
		WINDOW_WIDTH,
		WINDOW_HEIGHT,
		SDL_WINDOW_BORDERLESS
		);
	if(!app->window) {
		fprintf(stderr, "Error creating SDL_Window.\n");
		return FALSE;
	}
	app->renderer = SDL_CreateRenderer(app->window, -1, 0);
	if(!app->renderer) {
		fprintf(stderr, "Error creating SDL_Renderer");
		return FALSE;
	}
	IMG_Init(IMG_INIT_PNG);
	Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024);
	Mix_AllocateChannels(MAX_SND_CHANNELS);
	return TRUE;
}

void destroy_window(App *app) {
	SDL_DestroyRenderer(app->renderer);
	SDL_DestroyWindow(app->window);
	SDL_Quit();
}