Mercurial > molko
comparison src/core/image.c @ 111:f17890fe144b
image: can load a texture directly
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 08 Apr 2020 20:05:00 +0200 |
parents | ed72843a7194 |
children | 40f22a8188d2 |
comparison
equal
deleted
inserted
replaced
110:d3bc14c1e243 | 111:f17890fe144b |
---|---|
20 #include <stdbool.h> | 20 #include <stdbool.h> |
21 | 21 |
22 #include <SDL_image.h> | 22 #include <SDL_image.h> |
23 | 23 |
24 #include "error_p.h" | 24 #include "error_p.h" |
25 #include "texture_p.h" | 25 #include "texture.h" |
26 #include "window.h" | |
27 #include "window_p.h" | |
26 | 28 |
27 bool | 29 bool |
28 image_open(struct texture *tex, const char *path) | 30 image_open(struct texture *tex, const char *path) |
29 { | 31 { |
30 assert(tex); | 32 assert(tex); |
31 assert(path); | 33 assert(path); |
32 | 34 |
33 SDL_Surface *surface = IMG_Load(path); | 35 if (!(tex->handle = IMG_LoadTexture(RENDERER(), path))) |
34 | |
35 if (!surface) | |
36 return error_sdl(); | 36 return error_sdl(); |
37 | 37 |
38 return texture_from_surface(tex, surface); | 38 return true; |
39 } | 39 } |
40 | 40 |
41 bool | 41 bool |
42 image_openmem(struct texture *tex, const void *buffer, size_t size) | 42 image_openmem(struct texture *tex, const void *buffer, size_t size) |
43 { | 43 { |
44 assert(buffer); | 44 assert(buffer); |
45 | 45 |
46 SDL_RWops *ops = SDL_RWFromConstMem(buffer, size); | 46 SDL_RWops *ops = SDL_RWFromConstMem(buffer, size); |
47 SDL_Surface *surface; | |
48 | 47 |
49 if (!ops || !(surface = IMG_Load_RW(ops, true))) | 48 if (!ops || !(tex->handle = IMG_LoadTexture_RW(RENDERER(), ops, true))) |
50 return error_sdl(); | 49 return error_sdl(); |
51 | 50 |
52 return texture_from_surface(tex, surface); | 51 return true; |
53 } | 52 } |