-
Notifications
You must be signed in to change notification settings - Fork 4
/
asset_load.h
42 lines (37 loc) · 1.19 KB
/
asset_load.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include "SDL_gpu.h"
#include <SDL_ttf.h>
#include <SDL_mixer.h>
#include <cassert>
inline GPU_Image* LoadImage(const std::string& path) {
GPU_Image* texture = GPU_LoadImage(path.c_str());
if (!texture) {
Debug::out << "Unable to load image '" << path.c_str() << "': " << SDL_GetError();
assert(false);
return nullptr;
}
GPU_SetImageFilter(texture, GPU_FILTER_NEAREST);
GPU_SetSnapMode(texture, GPU_SNAP_NONE);
return texture;
}
inline TTF_Font* LoadFont(const std::string& path, int size) {
TTF_Font* font = TTF_OpenFont(path.c_str(), size);
if (!font) {
Debug::out << "Unable to load font '" << path.c_str() << "': " << TTF_GetError();
assert(false);
}
return font;
}
inline TTF_Font* LoadFontOutline(const std::string& path, int size, int outline) {
TTF_Font* font = LoadFont(path, size);
TTF_SetFontOutline(font, outline);
return font;
}
inline Mix_Music* LoadMusic(const std::string& path) {
Mix_Music* music = Mix_LoadMUS(path.c_str());
if (!music) {
Debug::out << "Unable to load music '" << path.c_str() << "': " << Mix_GetError();
assert(false);
}
return music;
}