Port of the official spine-sfml runtime to use SDL2 instead of SFML. It uses the new SDL_RenderGeometry functionality introduced in SDL2 2.0.18.
Just like spine-sfml, two different flavors are offered: one based on spine-c and one based on spine-cpp. They are in the c and cpp folders respectively.
- Spine animations exported for runtime 4.0.*
- SDL2 ≥ 2.0.18 and SDL_Image
- I also tested it with Emscripten 3.1.9.
See the c or cpp folders for examples and documentation.
-
The starting point was spine-sfml from the 4.0 branch. Since this implementation is part of the official runtimes, I tried to keep the logic unchanged.
-
I made some small improvements, such as:
- Made
getUsePremultipliedAlpha()
const - Refactored the blend mode logic into a single switch statement. Same performance, half the lines, more readable.
- spine-c version only:
- Removed the manual implementation for
spColorArray
and used the_SP_ARRAY_IMPLEMENT_TYPE
macro instead. This change required theoperator==
to be defined, but this is cleaner than writing the entire implementation by hand.
- Removed the manual implementation for
- Made
-
Replaced SFML with SDL2 as follows:
- Using the _SP_ARRAY macros, I created a new array type
spVertexArray
based onSDL_Vertex
and replaced all references tosf::VertexArray
with it. - Defined the blend modes with
SDL_ComposeCustomBlendMode
using GerogeChong's code as a starting point. - Used
SDL_SetTextureBlendMode
andSDL_RenderGeometry
for drawing. It's roughtly equivalent to what rmg-nik's did. - spine-c version only:
- Implemented
_spUtil_readFile
usingSDL_RWFromFile
,SDL_RWread
, etc. - Implemented
_spAtlasPage_createTexture
/_spAtlasPage_disposeTexture
usingIMG_Load
andSDL_CreateTextureFromSurface
. - Important: the previous step depends on a external function called
spSDL_getRenderer
that you have to implement yourself, but it's very easy: just return a pointer to the current SDL_Renderer
- Implemented
- spine-cpp version only:
- Replaced
SFMLTextureLoader
with a new classSDLTextureLoader
implemented usingIMG_Load
andSDL_CreateTextureFromSurface
. The constructor takes a pointer to the current SDL_Renderer (so there's no need to define an external function).
- Replaced
- Using the _SP_ARRAY macros, I created a new array type
-
Modified the examples from spine-sfml to use spine-sdl:
- Replaced the SFML loops with standard SDL loops.
- Replaced
sf::Mouse::getPosition
,window.clear()
andwindow.display()
withSDL_GetMouseState
,SDL_RenderClear
andSDL_RenderPresent
respectively. - Commented out the mix blends in the owl example because they don't seem to be working as intended.
- Fixes to the c examples:
- Leak #1: Calls to
spAnimationStateData_dispose
were missing. - Leak #2:
SkeletonDrawable
instances never get deleted, but we can create them on the stack like the cpp examples do.
- Leak #1: Calls to