mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 01:06:00 +08:00
[sdl] Use PMA asset in example, formatting, port to C backend
This commit is contained in:
parent
4cf43903c8
commit
cb3aa4ec7c
@ -225,8 +225,8 @@ cp -f ../celestial-circus/export/celestial-circus.png "$ROOT/spine-godot/example
|
||||
echo "spine-sdl"
|
||||
rm -f "$ROOT/spine-sdl/data/"*
|
||||
cp -f ../spineboy/export/spineboy-pro.json "$ROOT/spine-sdl/data/"
|
||||
cp -f ../spineboy/export/spineboy.atlas "$ROOT/spine-sdl/data/"
|
||||
cp -f ../spineboy/export/spineboy.png "$ROOT/spine-sdl/data/"
|
||||
cp -f ../spineboy/export/spineboy-pma.atlas "$ROOT/spine-sdl/data/"
|
||||
cp -f ../spineboy/export/spineboy-pma.png "$ROOT/spine-sdl/data/"
|
||||
|
||||
echo "spine-sfml-c"
|
||||
rm "$ROOT/spine-sfml/c/data/"*
|
||||
|
||||
@ -20,7 +20,7 @@ For the official legal terms governing the Spine Runtimes, please read the [Spin
|
||||
|
||||
spine-sdl works with data exported from Spine 4.2.xx.
|
||||
|
||||
spine-sdl supports all Spine features except premultiplied alpha, screen blend mode, and two color tinting.
|
||||
spine-sdl supports all Spine features except screen blend mode and two color tinting.
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
spineboy.png
|
||||
spineboy-pma.png
|
||||
size: 1024, 256
|
||||
filter: Linear, Linear
|
||||
pma: true
|
||||
scale: 0.5
|
||||
crosshair
|
||||
bounds: 352, 7, 45, 45
|
||||
BIN
spine-sdl/data/spineboy-pma.png
Normal file
BIN
spine-sdl/data/spineboy-pma.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 239 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 240 KiB |
@ -47,13 +47,14 @@ int main() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
spAtlas *atlas = spAtlas_createFromFile("data/spineboy.atlas", renderer);
|
||||
spAtlas *atlas = spAtlas_createFromFile("data/spineboy-pma.atlas", renderer);
|
||||
spSkeletonJson *json = spSkeletonJson_create(atlas);
|
||||
json->scale = 0.5f;
|
||||
spSkeletonData *skeletonData = spSkeletonJson_readSkeletonDataFile(json, "data/spineboy-pro.json");
|
||||
spAnimationStateData *animationStateData = spAnimationStateData_create(skeletonData);
|
||||
animationStateData->defaultMix = 0.2f;
|
||||
spSkeletonDrawable *drawable = spSkeletonDrawable_create(skeletonData, animationStateData);
|
||||
drawable->usePremultipliedAlpha = -1;
|
||||
drawable->skeleton->x = 400;
|
||||
drawable->skeleton->y = 500;
|
||||
spSkeleton_setToSetupPose(drawable->skeleton);
|
||||
|
||||
@ -48,12 +48,13 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
spine::SDLTextureLoader textureLoader(renderer);
|
||||
spine::Atlas atlas("data/spineboy.atlas", &textureLoader);
|
||||
spine::Atlas atlas("data/spineboy-pma.atlas", &textureLoader);
|
||||
spine::AtlasAttachmentLoader attachmentLoader(&atlas);
|
||||
spine::SkeletonJson json(&attachmentLoader);
|
||||
json.setScale(0.5f);
|
||||
spine::SkeletonData *skeletonData = json.readSkeletonDataFile("data/spineboy-pro.json");
|
||||
spine::SkeletonDrawable drawable(skeletonData);
|
||||
drawable.usePremultipliedAlpha = true;
|
||||
drawable.animationState->getData()->setDefaultMix(0.2f);
|
||||
drawable.skeleton->setPosition(400, 500);
|
||||
drawable.skeleton->setToSetupPose();
|
||||
|
||||
@ -42,6 +42,7 @@ spSkeletonDrawable *spSkeletonDrawable_create(spSkeletonData *skeletonData, spAn
|
||||
spSkeletonDrawable *self = NEW(spSkeletonDrawable);
|
||||
self->skeleton = spSkeleton_create(skeletonData);
|
||||
self->animationState = spAnimationState_create(animationStateData);
|
||||
self->usePremultipliedAlpha = 0;
|
||||
self->sdlIndices = spIntArray_create(12);
|
||||
self->sdlVertices = spSdlVertexArray_create(12);
|
||||
self->worldVertices = spFloatArray_create(12);
|
||||
@ -163,20 +164,41 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend
|
||||
for (int ii = 0; ii < (int) indicesCount; ii++)
|
||||
spIntArray_add(self->sdlIndices, indices[ii]);
|
||||
|
||||
switch (slot->data->blendMode) {
|
||||
case SP_BLEND_MODE_NORMAL:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
case SP_BLEND_MODE_MULTIPLY:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
break;
|
||||
case SP_BLEND_MODE_ADDITIVE:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
|
||||
break;
|
||||
case SP_BLEND_MODE_SCREEN:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
}
|
||||
if (!self->usePremultipliedAlpha) {
|
||||
switch (slot->data->blendMode) {
|
||||
case SP_BLEND_MODE_NORMAL:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
case SP_BLEND_MODE_MULTIPLY:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
break;
|
||||
case SP_BLEND_MODE_ADDITIVE:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
|
||||
break;
|
||||
case SP_BLEND_MODE_SCREEN:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
SDL_BlendMode target;
|
||||
switch (slot->data->blendMode) {
|
||||
case SP_BLEND_MODE_NORMAL:
|
||||
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, target);
|
||||
break;
|
||||
case SP_BLEND_MODE_MULTIPLY:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderGeometry(renderer, texture, self->sdlVertices->items, self->sdlVertices->size, self->sdlIndices->items,
|
||||
indicesCount);
|
||||
|
||||
@ -43,6 +43,7 @@ _SP_ARRAY_DECLARE_TYPE(spSdlVertexArray, struct SDL_Vertex)
|
||||
typedef struct spSkeletonDrawable {
|
||||
spSkeleton *skeleton;
|
||||
spAnimationState *animationState;
|
||||
int usePremultipliedAlpha;
|
||||
|
||||
spSkeletonClipping *clipper;
|
||||
spFloatArray *worldVertices;
|
||||
|
||||
@ -164,38 +164,37 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) {
|
||||
|
||||
if (!usePremultipliedAlpha) {
|
||||
switch (slot.getData().getBlendMode()) {
|
||||
case BlendMode_Normal:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
case BlendMode_Multiply:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
break;
|
||||
case BlendMode_Additive:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
|
||||
break;
|
||||
case BlendMode_Screen:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
case BlendMode_Normal:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
case BlendMode_Multiply:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
break;
|
||||
case BlendMode_Additive:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
|
||||
break;
|
||||
case BlendMode_Screen:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SDL_BlendMode target;
|
||||
switch (slot.getData().getBlendMode()) {
|
||||
case BlendMode_Normal:
|
||||
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, target);
|
||||
break;
|
||||
case BlendMode_Multiply:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
case BlendMode_Normal:
|
||||
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, target);
|
||||
break;
|
||||
case BlendMode_Multiply:
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -46,9 +46,7 @@ namespace spine {
|
||||
|
||||
Skeleton *skeleton;
|
||||
AnimationState *animationState;
|
||||
|
||||
void setUsePremultipliedAlpha(bool usePMA) { usePremultipliedAlpha = usePMA; };
|
||||
bool getUsePremultipliedAlpha() { return usePremultipliedAlpha; };
|
||||
bool usePremultipliedAlpha;
|
||||
|
||||
private:
|
||||
bool ownsAnimationStateData;
|
||||
@ -56,7 +54,6 @@ namespace spine {
|
||||
Vector<float> worldVertices;
|
||||
Vector<SDL_Vertex> sdlVertices;
|
||||
Vector<int> sdlIndices;
|
||||
bool usePremultipliedAlpha;
|
||||
};
|
||||
|
||||
class SDLTextureLoader : public spine::TextureLoader {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user