/*
 * DESCRIPTION:
 * Handles basic SDL functions.
*/

#include "sdl.h"

/* Initializes SDL. */
void
sdl_init(void)
{
	if (SDL_INIT_VIDEO < 0) 
	{
		printf(STRING_SDL2_VIDEO_ERROR);
		exit(EXIT_FAILURE);
	}
	else
		printf(STRING_SDL2_VIDEO_INIT);

	if (SDL_INIT_TIMER < 0) 
	{
		printf(STRING_SDL2_TIMER_ERROR);
		exit(EXIT_FAILURE);
	}
	else
		printf(STRING_SDL2_TIMER_INIT);

	if (IMG_Init(IMG_FLAGS) < 0) 
	{
		printf(STRING_SDL_IMAGE_ERROR);
		exit(EXIT_FAILURE);
	}
	else
		printf(STRING_SDL_IMAGE_INIT);

	if (TTF_Init() < 0) 
	{
		printf(STRING_SDL_TTF_ERROR);
		exit(EXIT_FAILURE);
	}
	else
		printf(STRING_SDL_TTF_INIT);

	if (Mix_OpenAudio(MIX_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_CHANNELS, MIX_SAMPLE_SIZE) < 0) 
	{
		printf(STRING_SDL_MIXER_ERROR);
		exit(EXIT_FAILURE);
	} 
	else
		printf(STRING_SDL_MIXER_INIT);

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

	SDL_ShowCursor(SDL_DISABLE);
}

/* Quits SDL. */
void
sdl_quit(void)
{
	printf(STRING_SDL2_QUIT);
	SDL_Quit();
}
