Has anybody successfully rendered a skeleton to a texture via Cocos2d-x? Even as a child of a valid node, nothing appears. I think this is because Cocos2d-x checks for how many children it has (which is zero).

Would a suitable solution be to make the renderer recursively go through the skeleton... I suppose mimic the drawing process as it would do normally to the buffer?

Related Discussions
...

Could you modify one of our Cocos2d-x samples to show the issue? I can have a look then.

Okay, after fiddling with the examples it turns out the rendering is fine. I suspect what is happening is that it's being drawn outside of the bounds of the texture, hence why I'm not seeing anything.

That being said, there's some unexpected behaviour when the skeleton is a child of a node. In the spineboy example I set the skeleton to be a child of a node and I set the position of this node to the original position. I then set the position of the skeleton to zero. When the render to texture is complete, the skeleton jumps to a world position of 0,0 and the rendered texture positions the skeleton at 0,0 in the image. Below is the modified code:

//SpineboyExample.cpp
//...
skeletonNode->setTrackStartListener(jumpEntry, [] (spTrackEntry* entry) {
      log("jumped!");
   });

   Node* node = Node::create();
    node->setPosition(Vec2(_contentSize.width / 2, 20));
    addChild(node);
    
//skeletonNode->setPosition(Vec2(_contentSize.width / 2, 20)); node->addChild(skeletonNode); scheduleUpdate(); EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool { const float reducedTimeScale = 0.3f; if (!skeletonNode->getDebugBonesEnabled()) skeletonNode->setDebugBonesEnabled(true); else if (skeletonNode->getTimeScale() == 1) skeletonNode->setTimeScale(reducedTimeScale); else if(skeletonNode->getTimeScale() == reducedTimeScale) {
auto testRenderTexture = RenderTexture::create(1024, 1024); testRenderTexture->begin(); skeletonNode->visit(); testRenderTexture->end(); testRenderTexture->saveToFile("test.png"); } else Director::getInstance()->replaceScene(GoblinsExample::scene()); return true; };

Any ideas/best practices on correctly placing the skeleton on a texture and also creating the acquiring the correct size for the texture (other than trial and error)?

OpenGL Render to texture space has a different Y space.

In my engine I have code similar to this:
_mtxProj._42 += (!_bRenderingToTarget) ? GL_FINALSCREEN_SHIFT : -GL_FINALSCREEN_SHIFT;

where the final screen shift is 2. However, If I were you I would try offsetting the screen Y coordinates by 1/2 the height of the screen. First in the positive direction and then in the negative direction.

I use 2 because this is a final shift where the coordinate range is [-1..1] . If you are doing this before your projection, then it will need to be the height of the screen.

So I've managed to get it to render to the texture... almost completely correctly... at the very least it's in the right position.

However, it would appear that not all of the skeleton is rendered as you can see below (there are supposed to be arms and legs):

Image removed due to the lack of support for HTTPS. | Show Anyway

The artist who made this has indicated that the limbs are:

... meshes with weight bindings on the verts. Everything else is a sprite..

Any ideas on how to correct this?

EDIT
I've managed to reproduce the error with the tank example. Simply apply similar code from the snippet I provided above. Everything except the aerial renders correctly.

Image removed due to the lack of support for HTTPS. | Show Anyway

Workaround
What we've done to get around this is to create a one frame animation, hide everything except optional attachments and drop in a sprite of the whole skeleton. This is fine so long as you don't want a "freeze action" shot, more of a pose.

Could you post your full modified SpineExample.cpp so I can repro here?

Using the tank example, rather than the spineboy example

/******************************************************************************
 * Spine Runtimes Software License v2.5
 *
 * Copyright (c) 2013-2016, Esoteric Software
 * All rights reserved.
 *
 * You are granted a perpetual, non-exclusive, non-sublicensable, and
 * non-transferable license to use, install, execute, and perform the Spine
 * Runtimes software and derivative works solely for personal or internal
 * use. Without the written permission of Esoteric Software (see Section 2 of
 * the Spine Software License Agreement), you may not (a) modify, translate,
 * adapt, or develop new applications using the Spine Runtimes or otherwise
 * create derivative works or improvements of the Spine Runtimes or (b) remove,
 * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
 * or other intellectual property or proprietary rights notices on or in the
 * Software, including any copy thereof. Redistributions in binary or source
 * form must include this license and terms.
 *
 * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
 * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/

#include "TankExample.h"
#include "BatchingExample.h"

USING_NS_CC;
using namespace spine;

Scene* TankExample::scene () {
   Scene *scene = Scene::create();
   scene->addChild(TankExample::create());
   return scene;
}

bool TankExample::init () {
   if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;

   skeletonNode = SkeletonAnimation::createWithJsonFile("tank.json", "tank.atlas", 0.5f);
   skeletonNode->setAnimation(0, "drive", true);

   skeletonNode->setPosition(Vec2(_contentSize.width / 2 + 400, 20));
   addChild(skeletonNode);

   scheduleUpdate();
   
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool { if (!skeletonNode->getDebugBonesEnabled()) skeletonNode->setDebugBonesEnabled(true); else if (skeletonNode->getTimeScale() == 1) skeletonNode->setTimeScale(0.3f); else { auto testRenderTexture = RenderTexture::create(1024, 1024); testRenderTexture->begin(); skeletonNode->visit(); testRenderTexture->end(); testRenderTexture->saveToFile("test.png"); Director::getInstance()->replaceScene(BatchingExample::scene()); } return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); return true; }

Sorry for the belated reply. Been a bit under water, I'll look into this asap.

Yeah, I'm inclined to agree as I saw some funny UV stuff going on as well and I observed no difference in the logic when stepping through it.

Question now is do we (the users) or you provide a workaround, or contact the Cocos guys and tell them something is off with their off screen rendering?

I think the best course of action is to create a minimal reproduction case, with a simpler Spine model, package that up with our runtime, not the one shipped by the Cocos2d-X team, and ask them what's up with their render to texture. We'd obviously appreciate if you could follow up with them.