[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.
This commit is contained in:
Luke Ingram 2025-10-13 13:59:58 -04:00
parent 3653540558
commit 2a25ca33d6
2 changed files with 10 additions and 6 deletions

View File

@ -73,6 +73,7 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend
spSkeletonClipping *clipper = self->clipper; spSkeletonClipping *clipper = self->clipper;
SDL_Texture *texture; SDL_Texture *texture;
SDL_Vertex sdlVertex; SDL_Vertex sdlVertex;
for (int i = 0; i < skeleton->slotsCount; ++i) { for (int i = 0; i < skeleton->slotsCount; ++i) {
spSlot *slot = skeleton->drawOrder[i]; spSlot *slot = skeleton->drawOrder[i];
spAttachment *attachment = slot->attachment; 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 g = (Uint8) (skeleton->color.g * slot->color.g * attachmentColor->g * 255);
Uint8 b = (Uint8) (skeleton->color.b * slot->color.b * attachmentColor->b * 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); Uint8 a = (Uint8) (skeleton->color.a * slot->color.a * attachmentColor->a * 255);
sdlVertex.color.r = r; sdlVertex.color.r = r;
sdlVertex.color.g = g; sdlVertex.color.g = g;
sdlVertex.color.b = b; sdlVertex.color.b = b;
@ -188,15 +190,16 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend
SDL_SetTextureBlendMode(texture, target); SDL_SetTextureBlendMode(texture, target);
break; break;
case SP_BLEND_MODE_MULTIPLY: 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; break;
case SP_BLEND_MODE_ADDITIVE: 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); 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; break;
case SP_BLEND_MODE_SCREEN: 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); 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; break;
} }
} }

View File

@ -115,15 +115,16 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) {
SDL_SetTextureBlendMode(texture, target); SDL_SetTextureBlendMode(texture, target);
break; break;
case BlendMode_Multiply: 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; break;
case BlendMode_Additive: case BlendMode_Additive:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD); 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; break;
case BlendMode_Screen: 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); 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; break;
} }
} }