#include "TZR.h" #include "TZR_globals.h" #include "sdl_error.h" #include #include #include static int _sdl_error(void) { sdl_error(-1); TZR_Quit(); return -1; } int _TZR_Init(const TZR_Config *config) { if (SDL_Init(SDL_INIT_VIDEO) < 0) return _sdl_error(); if (IMG_Init(IMG_INIT_PNG) < 0) return _sdl_error(); memcpy(&___tzr_config, config, sizeof(TZR_Config)); char *const basepath = SDL_GetBasePath(); if (basepath == NULL) return _sdl_error(); const int chdir_rv = chdir(basepath); SDL_free(basepath); if (chdir_rv < 0) return perror("TZR_Init"), -1; ___tzr_window = SDL_CreateWindow("TZR", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ___tzr_config.width, ___tzr_config.height, SDL_WINDOW_RESIZABLE); if (___tzr_window == NULL) return _sdl_error(); ___tzr_renderer = SDL_CreateRenderer(___tzr_window, -1, SDL_RENDERER_ACCELERATED); if (___tzr_renderer == NULL) return _sdl_error(); if (SDL_SetRenderDrawBlendMode(___tzr_renderer, SDL_BLENDMODE_BLEND)) return _sdl_error(); ___tzr_target = SDL_CreateTexture(___tzr_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, ___tzr_config.width, ___tzr_config.height); if (___tzr_target == NULL) return _sdl_error(); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0); ___tzr_tick = 0; if (___tzr_config.target_fps > 0) { ___tzr_min_dt = 1000 / ___tzr_config.target_fps; ___tzr_next_time = SDL_GetTicks64(); } if (!___tzr_config.show_cursor) SDL_ShowCursor(0); return 0; }