From 2a25ca33d65d55f05b1969659ee68b53f07d6c43 Mon Sep 17 00:00:00 2001 From: Luke Ingram Date: Mon, 13 Oct 2025 13:59:58 -0400 Subject: [PATCH] [c][cpp][sdl] Fixes, closes #2943. The reason that the chibi-stickers project wouldn't load correctly was because there was multiply blending used on the glasses-shadow slot. This has been corrected so that skeletons will load correctly, and tested using this project and the celestial-circus Spine project. --- spine-sdl/src/spine-sdl-c.c | 9 ++++++--- spine-sdl/src/spine-sdl-cpp.cpp | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spine-sdl/src/spine-sdl-c.c b/spine-sdl/src/spine-sdl-c.c index 3184c372f..c1b2f1576 100644 --- a/spine-sdl/src/spine-sdl-c.c +++ b/spine-sdl/src/spine-sdl-c.c @@ -73,6 +73,7 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend spSkeletonClipping *clipper = self->clipper; SDL_Texture *texture; SDL_Vertex sdlVertex; + for (int i = 0; i < skeleton->slotsCount; ++i) { spSlot *slot = skeleton->drawOrder[i]; spAttachment *attachment = slot->attachment; @@ -139,6 +140,7 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend Uint8 g = (Uint8) (skeleton->color.g * slot->color.g * attachmentColor->g * 255); Uint8 b = (Uint8) (skeleton->color.b * slot->color.b * attachmentColor->b * 255); Uint8 a = (Uint8) (skeleton->color.a * slot->color.a * attachmentColor->a * 255); + sdlVertex.color.r = r; sdlVertex.color.g = g; sdlVertex.color.b = b; @@ -188,15 +190,16 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend SDL_SetTextureBlendMode(texture, target); break; case SP_BLEND_MODE_MULTIPLY: - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD); + target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_DST_COLOR, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_DST_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD); + SDL_SetTextureBlendMode(texture, target); break; case SP_BLEND_MODE_ADDITIVE: target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD); + SDL_SetTextureBlendMode(texture, target); break; case SP_BLEND_MODE_SCREEN: target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + SDL_SetTextureBlendMode(texture, target); break; } } diff --git a/spine-sdl/src/spine-sdl-cpp.cpp b/spine-sdl/src/spine-sdl-cpp.cpp index 0662df2c6..3ba4442eb 100644 --- a/spine-sdl/src/spine-sdl-cpp.cpp +++ b/spine-sdl/src/spine-sdl-cpp.cpp @@ -115,15 +115,16 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) { SDL_SetTextureBlendMode(texture, target); break; case BlendMode_Multiply: - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD); + target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_DST_COLOR, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_DST_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD); + SDL_SetTextureBlendMode(texture, target); break; case BlendMode_Additive: target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD); + SDL_SetTextureBlendMode(texture, target); break; case BlendMode_Screen: target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + SDL_SetTextureBlendMode(texture, target); break; } }