diff options
| author | banana <delgadillo.tyler@gmail.com> | 2024-03-22 13:46:36 -0700 | 
|---|---|---|
| committer | banana <delgadillo.tyler@gmail.com> | 2024-03-22 13:46:36 -0700 | 
| commit | ad22993557296b02bc0c947cb3bb6247fac8f47f (patch) | |
| tree | 2c83ab589acab8a5074583d625d54ec44677e5d0 /initialize.c | |
Diffstat (limited to 'initialize.c')
| -rw-r--r-- | initialize.c | 40 | 
1 files changed, 40 insertions, 0 deletions
| diff --git a/initialize.c b/initialize.c new file mode 100644 index 0000000..75d9e2d --- /dev/null +++ b/initialize.c @@ -0,0 +1,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(); +} | 
