diff options
author | kdx <kikoodx@paranoici.org> | 2022-11-17 08:27:17 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2022-11-17 08:27:17 +0100 |
commit | 110f0ed5e3be41dbe226d045ab71ac2eb21073b3 (patch) | |
tree | b2a9ef25a8ba854bbc9cf5b5d88edc4fbeb7bc11 | |
parent | ae757fde37f1d5ec2875489d8db69e64075838e9 (diff) | |
download | lzr-110f0ed5e3be41dbe226d045ab71ac2eb21073b3.tar.gz |
configurable blend mode
-rw-r--r-- | demo.c | 4 | ||||
-rw-r--r-- | lzr.c | 15 | ||||
-rw-r--r-- | lzr.h | 1 |
3 files changed, 17 insertions, 3 deletions
@@ -1,11 +1,13 @@ #include "lzr.h" +#include <SDL2/SDL_blendmode.h> #include <SDL2/SDL_scancode.h> #include <dx/log.h> #include <stdbool.h> int main(void) { - LZR_Config cfg = {400, 224, 60, 16, "LZR demo", false}; + LZR_Config cfg = { + 400, 224, 60, 16, "LZR demo", false, SDL_BLENDMODE_MUL}; if (LZR_Init(cfg)) return 1; LZR_ImageLoad("coucou.bmp"); @@ -4,6 +4,7 @@ #include <SDL2/SDL2_gfxPrimitives.h> #include <SDL2/SDL_image.h> #include <SDL2/SDL_mixer.h> +#include <SDL2/SDL_render.h> #include <dx/log.h> #include <dx/mem.h> #include <dx/str.h> @@ -37,6 +38,7 @@ static SDL_Point *points = NULL; static uint64_t tick = 0; static Mix_Chunk *sounds[LZR_MAX_SOUNDS] = {0}; static Mix_Music *music = NULL; +static SDL_BlendMode blend_mode = SDL_BLENDMODE_NONE; static int _scode_to_button(unsigned int scode) { @@ -287,6 +289,11 @@ int LZR_ImageLoad(const char *path) return -1; } images[i].tex = tex; + blend_mode = config.blend_mode; + if (SDL_SetTextureBlendMode(images[i].tex, blend_mode) < 0) { + dx_log_error("%s", SDL_GetError()); + return -1; + } if (SDL_QueryTexture(tex, NULL, NULL, &images[i].width, &images[i].height)) { dx_log_error("%s", SDL_GetError()); @@ -399,6 +406,10 @@ int LZR_DrawBegin(void) dx_log_error("%s", SDL_GetError()); return -1; } + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + SDL_SetRenderDrawBlendMode(renderer, blend_mode); return 0; } @@ -408,6 +419,7 @@ int LZR_DrawEnd(void) dx_log_error("%s", SDL_GetError()); return -1; } + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); LZR_DrawSetColor(0.0f, 0.0f, 0.0f); if (LZR_DrawClear()) { dx_log_error("LZY_DrawClear failed"); @@ -429,8 +441,7 @@ int LZR_DrawEnd(void) const int off_y = (win_h - config.display_height * scale) / 2; const SDL_Rect dest = {off_x, off_y, config.display_width * scale, config.display_height * scale}; - if (SDL_RenderCopyEx(renderer, target, NULL, &dest, 0.0, NULL, 0) < - 0) { + if (SDL_RenderCopyEx(renderer, target, NULL, &dest, 0.0, NULL, 0) < 0) { dx_log_error("%s", SDL_GetError()); return -1; } @@ -15,6 +15,7 @@ typedef struct LZR_Config { unsigned int tile_size; const char *title; bool disable_bind_menu; + unsigned int blend_mode; } LZR_Config; typedef enum LZR_EventType { |