57 lines
1.1 KiB
C
57 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include "init_sdl.h"
|
|
|
|
void initWindow(SDL_Window **win, TTF_Font **font, char *t, int h, int w){
|
|
if(SDL_Init(SDL_INIT_VIDEO) != 0){
|
|
printf("SDL: Failed to init sdl: %s\n", SDL_GetError());
|
|
exit(1);
|
|
}
|
|
//SDL_Window *win;
|
|
*win = SDL_CreateWindow(t, SDL_WINDOWPOS_UNDEFINED,
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
w, h,
|
|
SDL_WINDOW_SHOWN);
|
|
|
|
/* Init TTF */
|
|
if(TTF_Init() != 0){
|
|
printf("SDL: Failed to init TTF: %s\n", SDL_GetError());
|
|
SDL_Quit();
|
|
exit(1);
|
|
}
|
|
|
|
*font = TTF_OpenFont("sdl/fonts/FreeSans.otf", 25);
|
|
|
|
if(*win == NULL){
|
|
printf("SDL: Failed to init SDL\n");
|
|
TTF_Quit();
|
|
SDL_Quit();
|
|
exit(1);
|
|
}
|
|
|
|
if (*font == NULL){
|
|
printf("SDL: Failed to open font\n");
|
|
SDL_DestroyWindow(*win);
|
|
TTF_Quit();
|
|
SDL_Quit();
|
|
exit(1);
|
|
}
|
|
}
|
|
SDL_Surface *loadImage(const char *filename){
|
|
SDL_Surface *s = IMG_Load(filename);
|
|
if(s == NULL) {
|
|
printf("SDL: Failed to load img\n");
|
|
return NULL;
|
|
}
|
|
return s;
|
|
}
|
|
void destroyWindow(SDL_Window *w, SDL_Renderer *r, TTF_Font *f){
|
|
if (f != NULL)
|
|
TTF_CloseFont(f);
|
|
if (r != NULL)
|
|
SDL_DestroyRenderer(r);
|
|
if (w != NULL)
|
|
SDL_DestroyWindow(w);
|
|
TTF_Quit();
|
|
SDL_Quit();
|
|
}
|