Mercurial > molko
changeset 184:c92957c3b82b
core: add texture_set_(alpha|color)_mod functions
Apply either an alpha transparency modulation or a color on the texture.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 02 Nov 2020 18:35:44 +0100 |
parents | 604fad63bd9c |
children | 7103d6574062 |
files | libcore/core/texture.c libcore/core/texture.h |
diffstat | 2 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libcore/core/texture.c Mon Nov 02 13:42:51 2020 +0100 +++ b/libcore/core/texture.c Mon Nov 02 18:35:44 2020 +0100 @@ -18,6 +18,7 @@ #include <assert.h> +#include "color.h" #include "error.h" #include "texture.h" #include "texture_p.h" @@ -51,6 +52,29 @@ } bool +texture_set_alpha_mod(struct texture *tex, unsigned int alpha) +{ + assert(texture_ok(tex)); + assert(alpha <= 255); + + if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0) + return errorf("%s", SDL_GetError()); + + return true; +} + +bool +texture_set_color_mod(struct texture *tex, unsigned long color) +{ + assert(texture_ok(tex)); + + if (SDL_SetTextureColorMod(tex->handle, COLOR_R(color), COLOR_G(color), COLOR_B(color)) < 0) + return errorf("%s", SDL_GetError()); + + return true; +} + +bool texture_draw(const struct texture *tex, int x, int y) { assert(tex);
--- a/libcore/core/texture.h Mon Nov 02 13:42:51 2020 +0100 +++ b/libcore/core/texture.h Mon Nov 02 18:35:44 2020 +0100 @@ -65,6 +65,26 @@ texture_ok(const struct texture *tex); /** + * Apply an alpha modulation (aka transparency). + * + * \pre texture_ok(tex) + * \param tex the texture + * \param alpha the alpha (0-255) + */ +bool +texture_set_alpha_mod(struct texture *tex, unsigned int alpha); + +/** + * Apply a color modulation (for every pixel). + * + * \pre texture_ok(tex) + * \param tex the texture to modify + * \param color the color + */ +bool +texture_set_color_mod(struct texture *tex, unsigned long color); + +/** * Simple texture drawing. * * \pre tex != NULL