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
spColorArrayand used the_SP_ARRAY_IMPLEMENT_TYPEmacro 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
spVertexArraybased onSDL_Vertexand replaced all references tosf::VertexArraywith it. - Defined the blend modes with
SDL_ComposeCustomBlendModeusing GerogeChong's code as a starting point. - Used
SDL_SetTextureBlendModeandSDL_RenderGeometryfor drawing. It's roughtly equivalent to what rmg-nik's did. - spine-c version only:
- Implemented
_spUtil_readFileusingSDL_RWFromFile,SDL_RWread, etc. - Implemented
_spAtlasPage_createTexture/_spAtlasPage_disposeTextureusingIMG_LoadandSDL_CreateTextureFromSurface. - Important: the previous step depends on a external function called
spSDL_getRendererthat 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
SFMLTextureLoaderwith a new classSDLTextureLoaderimplemented usingIMG_LoadandSDL_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_RenderClearandSDL_RenderPresentrespectively. - 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_disposewere missing. - Leak #2:
SkeletonDrawableinstances never get deleted, but we can create them on the stack like the cpp examples do.
- Leak #1: Calls to