Files
orbit-plus/src/engine/sdl.c
2023-02-11 23:18:45 -05:00

66 lines
1.1 KiB
C

/*
* DESCRIPTION:
* Handles basic SDL functions.
*/
#include "sdl.h"
/* Initializes SDL. */
void
sdl_init(void)
{
if (SDL_INIT_VIDEO < 0)
{
printf("SDL2 ERROR: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
else
printf("SDL2 VIDEO LOADED\n");
if (SDL_INIT_TIMER < 0)
{
printf("SDL2 ERROR: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
else
printf("SDL2 TIMER LOADED\n");
if (IMG_Init(IMG_FLAGS) < 0)
{
printf("SDL_image ERROR: %s\n", IMG_GetError());
exit(EXIT_FAILURE);
}
else
printf("SDL_image LOADED\n");
if (TTF_Init() < 0)
{
printf("SDL_ttf ERROR: %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
else
printf("SDL_ttf LOADED\n");
if (Mix_OpenAudio(MIX_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_CHANNELS, MIX_SAMPLE_SIZE) < 0)
{
printf("SDL_mixer ERROR: %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
else
printf("SDL_mixer LOADED\n");
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);
}
/* Quits SDL. */
void
sdl_quit(void)
{
SDL_Quit();
Mix_CloseAudio();
IMG_Quit();
}