-
Notifications
You must be signed in to change notification settings - Fork 2
/
img_stub.h
52 lines (44 loc) · 944 Bytes
/
img_stub.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
43
44
45
46
47
48
49
50
51
52
#ifndef VIOLET_IMG_STUB_H
#define VIOLET_IMG_STUB_H
typedef struct gui_img
{
u32 handle;
u32 width;
u32 height;
u32 blend;
} gui_img_t;
typedef enum gui_blend
{
GUI_BLEND_NRM,
GUI_BLEND_ADD,
GUI_BLEND_MUL,
GUI_BLEND__COUNT
} gui_blend_e;
b32 img_load(gui_img_t *img, const char *filename);
void img_destroy(gui_img_t *img);
#endif // VIOLET_IMG_STUB_H
#ifdef IMG_STUB_IMPLEMENTATION
b32 img_load(gui_img_t *img, const char *filename)
{
b32 ret = false;
int w, h;
stbi_set_flip_vertically_on_load(true);
u8 *image = stbi_load(filename, &w, &h, NULL, 4);
if (image) {
img->handle = 42; /* don't use 0 - represents NULL in OpenGL */
img->width = w;
img->height = h;
img->blend = 0;
stbi_image_free(image);
ret = true;
} else {
log_error("img_load(%s) error", filename);
}
return ret;
}
void img_destroy(gui_img_t *img)
{
img->handle = 0;
}
#undef IMG_STUB_IMPLEMENTATION
#endif // IMG_STUB_IMPLEMENTATION