55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
|
|
#include "sdl_starter.h"
|
|
#include <SDL2/SDL_image.h>
|
|
#include <SDL2/SDL_mixer.h>
|
|
#include <SDL2/SDL_ttf.h>
|
|
#include <stdio.h>
|
|
|
|
int startSDL(SDL_Window *window, SDL_Renderer *renderer) {
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
|
|
{
|
|
printf("SDL crashed. Error: %s\n", SDL_GetError());
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (window == NULL)
|
|
{
|
|
fprintf(stderr, "Failed to create window: %s\n", SDL_GetError());
|
|
SDL_Quit();
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (renderer == NULL)
|
|
{
|
|
fprintf(stderr, "Failed to create renderer: %s\n", SDL_GetError());
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (!IMG_Init(IMG_INIT_PNG))
|
|
{
|
|
printf("SDL_image crashed. Error: %s\n", SDL_GetError());
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
|
|
{
|
|
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
|
|
return 1;
|
|
}
|
|
|
|
|
|
if (TTF_Init() == -1)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
} |