Skip to content

Spine Runtime for SDL2 ≥ 2.0.18 using SDL_RenderGeometry

License

Notifications You must be signed in to change notification settings

royalstream/spine-sdl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spine Runtime for SDL2

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.

Version Requirements

  • Spine animations exported for runtime 4.0.*
  • SDL2 ≥ 2.0.18 and SDL_Image
  • I also tested it with Emscripten 3.1.9.

Documentation

See the c or cpp folders for examples and documentation.

Implementation Details (you may skip this)

  1. 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.

  2. 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 the operator== to be defined, but this is cleaner than writing the entire implementation by hand.
  3. Replaced SFML with SDL2 as follows:

    • Using the _SP_ARRAY macros, I created a new array type spVertexArray based on SDL_Vertex and replaced all references to sf::VertexArray with it.
    • Defined the blend modes with SDL_ComposeCustomBlendMode using GerogeChong's code as a starting point.
    • Used SDL_SetTextureBlendMode and SDL_RenderGeometry for drawing. It's roughtly equivalent to what rmg-nik's did.
    • spine-c version only:
      • Implemented _spUtil_readFile using SDL_RWFromFile, SDL_RWread, etc.
      • Implemented _spAtlasPage_createTexture/_spAtlasPage_disposeTexture using IMG_Load and SDL_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
    • spine-cpp version only:
      • Replaced SFMLTextureLoader with a new class SDLTextureLoader implemented using IMG_Load and SDL_CreateTextureFromSurface. The constructor takes a pointer to the current SDL_Renderer (so there's no need to define an external function).
  4. Modified the examples from spine-sfml to use spine-sdl:

    • Replaced the SFML loops with standard SDL loops.
    • Replaced sf::Mouse::getPosition, window.clear() and window.display() with SDL_GetMouseState, SDL_RenderClear and SDL_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.

About

Spine Runtime for SDL2 ≥ 2.0.18 using SDL_RenderGeometry

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages