I'm trying to learn how the spine-c runtimes work and in order to do so I'm trying to do something as simple as just showing a single image from the skeleton on the screen (I'm using the most recent spine-c runtimes with the export example spinboy files). The problem is the texture that is displaying does not seem to match the one I specify in code, no matter which image I try and display. My only guess is that the uvs for the image are somehow incorrect? Here is my code so far:
[code] typedef struct Vertex {
//All members are just structs with data (x,y - u,v - r,g,b,a;)
Position position{ 0.0f, 0.0f };
// UV coordinates
UVs uvs{ 0.0f, 0.0f };
//Don't care about color right now so just using default values
Color color{ 0.1f, 0.1f, 0.1f, 1.0f };
} Vertex;
void addVertex(float x, float y, float u, float v, int* index) {
Vertex* vertex = &vertices[*index];
vertex->position.x = x;
vertex->position.y = y;
vertex->uvs.u = u;
vertex->uvs.v = v;
vertex->color.r = .1f;
vertex->color.g = .1f;
vertex->color.b = .1f;
vertex->color.a = 1.0f;
*index += 1;
}
const uint16 maxVerticesPerAttachment = 2048;
float worldVerticesPositions[maxVerticesPerAttachment];
Vertex vertices[maxVerticesPerAttachment];
spAtlas* atlas = spAtlas_createFromFile("spineboy.atlas", 0);
spSkeletonJson* json = spSkeletonJson_create(atlas);
spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, "spineboy-ess.json");
spSkeletonJson_dispose(json);
spSkeleton* skeleton = spSkeleton_create(skeletonData);
skeleton->x = 500.0f;
skeleton->y = 100.0f;
spSkeleton_setBonesToSetupPose(skeleton);
spSkeleton_updateWorldTransform(skeleton);
spBone* bone = spSkeleton_findBone(skeleton, "front-fist");
spSlot* slot = spSkeleton_findSlot(skeleton, "front-fist");
spAttachment* attachment = slot->attachment;
spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment;
Blz::Graphics::Texture* texture = nullptr;
//Those i's are suppose to be pointer symbols. Don't know why this chat isn't letting me use that symbol here
texture = (Blz::Graphics::Texture)((spAtlasRegion)regionAttachment->rendererObject)->page->rendererObject;
spRegionAttachment_computeWorldVertices(regionAttachment, bone, worldVerticesPositions, 0, 2);
int index = 0;
addVertex(worldVerticesPositions[0], worldVerticesPositions[1], regionAttachment->uvs[0], regionAttachment->uvs[1], &index);
addVertex(worldVerticesPositions[2], worldVerticesPositions[3], regionAttachment->uvs[2], regionAttachment->uvs[3], &index);
addVertex(worldVerticesPositions[4], worldVerticesPositions[5], regionAttachment->uvs[4], regionAttachment->uvs[5], &index);
addVertex(worldVerticesPositions[4], worldVerticesPositions[5], regionAttachment->uvs[4], regionAttachment->uvs[5], &index);
addVertex(worldVerticesPositions[6], worldVerticesPositions[7], regionAttachment->uvs[6], regionAttachment->uvs[7], &index);
addVertex(worldVerticesPositions[0], worldVerticesPositions[1], regionAttachment->uvs[0], regionAttachment->uvs[1], &index);
//Send down 'vertices' for renderer to draw [/code]
and in the spAtlasPage_CreateTexture() function, I have the following implementation:
[code]void _spAtlasPage_createTexture(spAtlasPage* page, const char* path)
{
RUNTIME_ASSERT(page != nullptr, "Atlas Page was not loaded properly!");
Blz::Graphics::Texture* p_texture = new Blz::Graphics::Texture(path);
RUNTIME_ASSERT(p_texture != nullptr, "Atlas texture did no load properly!");
page->rendererObject = p_texture;
page->width = p_texture->GetWidth();
page->height = p_texture->GetHeight();
} [/code]
As you can see, I'm trying to display the front-fist image, but instead I'm getting a portion of the goggles image (again, from the sample, 'spineboy.png' image). Is there a function or step I'm missing to fix offsets for the images or something?