blob: 5adaf6a7c4cbcd443f85e91ebac5dc820719d04f (
plain)
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
43
44
45
46
47
48
49
50
51
|
#include "FLD.hpp"
static FLD::Image&
invalid_image(FLD *fld)
{
static FLD::Image image = { .fld = fld, .valid = false };
return image;
}
FLD::Image&
FLD::image(const std::string &path)
{
if (images.contains(path))
return images[path];
const auto surf = SDL_LoadBMP(path.c_str());
if (surf == nullptr) {
sdlError(path);
return invalid_image(this);
}
const auto tex = SDL_CreateTextureFromSurface(_renderer, surf);
SDL_FreeSurface(surf);
if (tex == nullptr) {
sdlError(path);
return invalid_image(this);
}
if (SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND) < 0) {
SDL_DestroyTexture(tex);
sdlError(path);
return invalid_image(this);
}
int width, height;
if (SDL_QueryTexture(tex, nullptr, nullptr, &width, &height) < 0) {
SDL_DestroyTexture(tex);
sdlError(path);
return invalid_image(this);
}
images[path] = {
.fld = this,
.path = path,
.ptr = tex,
.width = width,
.height = height
};
return images[path];
}
|