mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +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"
|
echo "spine-sdl"
|
||||||
rm -f "$ROOT/spine-sdl/data/"*
|
rm -f "$ROOT/spine-sdl/data/"*
|
||||||
cp -f ../spineboy/export/spineboy-pro.json "$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-pma.atlas "$ROOT/spine-sdl/data/"
|
||||||
cp -f ../spineboy/export/spineboy.png "$ROOT/spine-sdl/data/"
|
cp -f ../spineboy/export/spineboy-pma.png "$ROOT/spine-sdl/data/"
|
||||||
|
|
||||||
echo "spine-sfml-c"
|
echo "spine-sfml-c"
|
||||||
rm "$ROOT/spine-sfml/c/data/"*
|
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 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
|
## Usage
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
spineboy.png
|
spineboy-pma.png
|
||||||
size: 1024, 256
|
size: 1024, 256
|
||||||
filter: Linear, Linear
|
filter: Linear, Linear
|
||||||
|
pma: true
|
||||||
scale: 0.5
|
scale: 0.5
|
||||||
crosshair
|
crosshair
|
||||||
bounds: 352, 7, 45, 45
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
spAtlas *atlas = spAtlas_createFromFile("data/spineboy.atlas", renderer);
|
spAtlas *atlas = spAtlas_createFromFile("data/spineboy-pma.atlas", renderer);
|
||||||
spSkeletonJson *json = spSkeletonJson_create(atlas);
|
spSkeletonJson *json = spSkeletonJson_create(atlas);
|
||||||
json->scale = 0.5f;
|
json->scale = 0.5f;
|
||||||
spSkeletonData *skeletonData = spSkeletonJson_readSkeletonDataFile(json, "data/spineboy-pro.json");
|
spSkeletonData *skeletonData = spSkeletonJson_readSkeletonDataFile(json, "data/spineboy-pro.json");
|
||||||
spAnimationStateData *animationStateData = spAnimationStateData_create(skeletonData);
|
spAnimationStateData *animationStateData = spAnimationStateData_create(skeletonData);
|
||||||
animationStateData->defaultMix = 0.2f;
|
animationStateData->defaultMix = 0.2f;
|
||||||
spSkeletonDrawable *drawable = spSkeletonDrawable_create(skeletonData, animationStateData);
|
spSkeletonDrawable *drawable = spSkeletonDrawable_create(skeletonData, animationStateData);
|
||||||
|
drawable->usePremultipliedAlpha = -1;
|
||||||
drawable->skeleton->x = 400;
|
drawable->skeleton->x = 400;
|
||||||
drawable->skeleton->y = 500;
|
drawable->skeleton->y = 500;
|
||||||
spSkeleton_setToSetupPose(drawable->skeleton);
|
spSkeleton_setToSetupPose(drawable->skeleton);
|
||||||
|
|||||||
@ -48,12 +48,13 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
spine::SDLTextureLoader textureLoader(renderer);
|
spine::SDLTextureLoader textureLoader(renderer);
|
||||||
spine::Atlas atlas("data/spineboy.atlas", &textureLoader);
|
spine::Atlas atlas("data/spineboy-pma.atlas", &textureLoader);
|
||||||
spine::AtlasAttachmentLoader attachmentLoader(&atlas);
|
spine::AtlasAttachmentLoader attachmentLoader(&atlas);
|
||||||
spine::SkeletonJson json(&attachmentLoader);
|
spine::SkeletonJson json(&attachmentLoader);
|
||||||
json.setScale(0.5f);
|
json.setScale(0.5f);
|
||||||
spine::SkeletonData *skeletonData = json.readSkeletonDataFile("data/spineboy-pro.json");
|
spine::SkeletonData *skeletonData = json.readSkeletonDataFile("data/spineboy-pro.json");
|
||||||
spine::SkeletonDrawable drawable(skeletonData);
|
spine::SkeletonDrawable drawable(skeletonData);
|
||||||
|
drawable.usePremultipliedAlpha = true;
|
||||||
drawable.animationState->getData()->setDefaultMix(0.2f);
|
drawable.animationState->getData()->setDefaultMix(0.2f);
|
||||||
drawable.skeleton->setPosition(400, 500);
|
drawable.skeleton->setPosition(400, 500);
|
||||||
drawable.skeleton->setToSetupPose();
|
drawable.skeleton->setToSetupPose();
|
||||||
|
|||||||
@ -42,6 +42,7 @@ spSkeletonDrawable *spSkeletonDrawable_create(spSkeletonData *skeletonData, spAn
|
|||||||
spSkeletonDrawable *self = NEW(spSkeletonDrawable);
|
spSkeletonDrawable *self = NEW(spSkeletonDrawable);
|
||||||
self->skeleton = spSkeleton_create(skeletonData);
|
self->skeleton = spSkeleton_create(skeletonData);
|
||||||
self->animationState = spAnimationState_create(animationStateData);
|
self->animationState = spAnimationState_create(animationStateData);
|
||||||
|
self->usePremultipliedAlpha = 0;
|
||||||
self->sdlIndices = spIntArray_create(12);
|
self->sdlIndices = spIntArray_create(12);
|
||||||
self->sdlVertices = spSdlVertexArray_create(12);
|
self->sdlVertices = spSdlVertexArray_create(12);
|
||||||
self->worldVertices = spFloatArray_create(12);
|
self->worldVertices = spFloatArray_create(12);
|
||||||
@ -163,6 +164,7 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend
|
|||||||
for (int ii = 0; ii < (int) indicesCount; ii++)
|
for (int ii = 0; ii < (int) indicesCount; ii++)
|
||||||
spIntArray_add(self->sdlIndices, indices[ii]);
|
spIntArray_add(self->sdlIndices, indices[ii]);
|
||||||
|
|
||||||
|
if (!self->usePremultipliedAlpha) {
|
||||||
switch (slot->data->blendMode) {
|
switch (slot->data->blendMode) {
|
||||||
case SP_BLEND_MODE_NORMAL:
|
case SP_BLEND_MODE_NORMAL:
|
||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||||
@ -176,6 +178,26 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend
|
|||||||
case SP_BLEND_MODE_SCREEN:
|
case SP_BLEND_MODE_SCREEN:
|
||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||||
break;
|
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,
|
SDL_RenderGeometry(renderer, texture, self->sdlVertices->items, self->sdlVertices->size, self->sdlIndices->items,
|
||||||
|
|||||||
@ -43,6 +43,7 @@ _SP_ARRAY_DECLARE_TYPE(spSdlVertexArray, struct SDL_Vertex)
|
|||||||
typedef struct spSkeletonDrawable {
|
typedef struct spSkeletonDrawable {
|
||||||
spSkeleton *skeleton;
|
spSkeleton *skeleton;
|
||||||
spAnimationState *animationState;
|
spAnimationState *animationState;
|
||||||
|
int usePremultipliedAlpha;
|
||||||
|
|
||||||
spSkeletonClipping *clipper;
|
spSkeletonClipping *clipper;
|
||||||
spFloatArray *worldVertices;
|
spFloatArray *worldVertices;
|
||||||
|
|||||||
@ -177,8 +177,7 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) {
|
|||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
SDL_BlendMode target;
|
SDL_BlendMode target;
|
||||||
switch (slot.getData().getBlendMode()) {
|
switch (slot.getData().getBlendMode()) {
|
||||||
case BlendMode_Normal:
|
case BlendMode_Normal:
|
||||||
|
|||||||
@ -46,9 +46,7 @@ namespace spine {
|
|||||||
|
|
||||||
Skeleton *skeleton;
|
Skeleton *skeleton;
|
||||||
AnimationState *animationState;
|
AnimationState *animationState;
|
||||||
|
bool usePremultipliedAlpha;
|
||||||
void setUsePremultipliedAlpha(bool usePMA) { usePremultipliedAlpha = usePMA; };
|
|
||||||
bool getUsePremultipliedAlpha() { return usePremultipliedAlpha; };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ownsAnimationStateData;
|
bool ownsAnimationStateData;
|
||||||
@ -56,7 +54,6 @@ namespace spine {
|
|||||||
Vector<float> worldVertices;
|
Vector<float> worldVertices;
|
||||||
Vector<SDL_Vertex> sdlVertices;
|
Vector<SDL_Vertex> sdlVertices;
|
||||||
Vector<int> sdlIndices;
|
Vector<int> sdlIndices;
|
||||||
bool usePremultipliedAlpha;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SDLTextureLoader : public spine::TextureLoader {
|
class SDLTextureLoader : public spine::TextureLoader {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user