[sdl] Add stb_image.h for image loading.

This commit is contained in:
Mario Zechner 2022-07-29 17:01:27 +02:00
parent e7043f3bd2
commit a03c92f7f2
3 changed files with 7978 additions and 8 deletions

View File

@ -15,15 +15,15 @@ FetchContent_MakeAvailable(SDL)
include_directories(src)
add_library(spine-sdl-c STATIC src/spine-sdl-c.c src/spine-sdl-c.h)
add_library(spine-sdl-c STATIC src/spine-sdl-c.c src/spine-sdl-c.h src/stb_image.h)
target_link_libraries(spine-sdl-c LINK_PUBLIC spine-c)
install(TARGETS spine-sdl-c DESTINATION dist/lib)
install(FILES src/spine-sdl-c.h DESTINATION dist/include)
install(FILES src/spine-sdl-c.h src/stb_image.h DESTINATION dist/include)
add_library(spine-sdl-cpp STATIC src/spine-sdl-cpp.cpp src/spine-sdl-cpp.h)
add_library(spine-sdl-cpp STATIC src/spine-sdl-cpp.cpp src/spine-sdl-cpp.h src/stb_image.h)
target_link_libraries(spine-sdl-cpp LINK_PUBLIC spine-cpp)
install(TARGETS spine-sdl-cpp DESTINATION dist/lib)
install(FILES src/spine-sdl-cpp.h DESTINATION dist/include)
install(FILES src/spine-sdl-cpp.h src/stb_image.h DESTINATION dist/include)
add_executable(spine-sdl-c-example example/main.c)
target_link_libraries(spine-sdl-c-example SDL2 spine-sdl-c)

View File

@ -1,22 +1,95 @@
#include <SDL.h>
#include <spine-sdl-cpp.h>
#include <spine/spine.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
namespace spine {
struct SkeletonDrawable {
Skeleton *skeleton;
bool ownsAnimationStateData;
AnimationState *animationState;
SkeletonDrawable(SkeletonData *skeletonData, AnimationStateData *animationStateData = nullptr) {
Bone::setYDown(true);
skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
ownsAnimationStateData = animationStateData == 0;
if (ownsAnimationStateData) animationStateData = new (__FILE__, __LINE__) AnimationStateData(skeletonData);
animationState = new (__FILE__, __LINE__) AnimationState(animationStateData);
}
~SkeletonDrawable() {
if (ownsAnimationStateData) delete animationState->getData();
delete animationState;
delete skeleton;
}
void update(float delta) {
animationState->update(delta);
animationState->apply(*skeleton);
skeleton->updateWorldTransform();
}
void draw() {
}
};
class SDLTextureLoader: public spine::TextureLoader {
void load(AtlasPage &page, const String &path) {
/*Texture *texture = new Texture();
if (!texture->loadFromFile(path.buffer())) return;
if (page.magFilter == TextureFilter_Linear) texture->setSmooth(true);
if (page.uWrap == TextureWrap_Repeat && page.vWrap == TextureWrap_Repeat) texture->setRepeated(true);
page.setRendererObject(texture);
Vector2u size = texture->getSize();
page.width = size.x;
page.height = size.y;*/
}
void unload(void *texture) {
// delete (Texture *) texture;
}
};
SpineExtension *getDefaultExtension() {
return new DefaultSpineExtension();
}
}
void loadSkeleton(const char *json, const char *skel, const char *atlas) {
}
int main() {
SDL_Window *window = nullptr;
SDL_Surface *surface = nullptr;
if (SDL_Init(SDL_INIT_VIDEO)) {
printf("Error: %s", SDL_GetError());
return -1;
}
window = SDL_CreateWindow("Spine SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
SDL_Window *window = SDL_CreateWindow("Spine SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480,
SDL_WINDOW_SHOWN);
if (!window) {
printf("Error: %s", SDL_GetError());
return -1;
}
SDL_Surface *surface = SDL_GetWindowSurface(window);
spine::SkeletonDrawable skeletonDrawable(nullptr, nullptr);
bool exit = false;
do {
SDL_Event event;
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT)
exit = true;
}
} while (!exit);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}

7897
spine-sdl/src/stb_image.h Normal file

File diff suppressed because it is too large Load Diff