c++ - Cocos2d-x v3 : ClippingNode not working on RenderTexture

标签 c++ cocos2d-x cocos2d-x-3.0

如果 ClippingNode 被渲染到 RenderTexture 而不是作为子节点添加(或者在我的例子中添加到一个本身被渲染到 RenderTexture 的容器),效果就会被破坏:

Sprite 未被 mask (模板无效),屏幕的所有其余部分都填充为白色(在 ClippingNode 添加到所有其他层之上的情况下)。

(在ios和win32上测试过)

auto stencil = DrawNode::create();
static Point triangle[3];
triangle[0] = Point(-40, -40);
triangle[1] = Point(40, -40);
triangle[2] = Point(0, 40);
static Color4F green(0, 1, 0, 1);
stencil->drawPolygon(triangle, 3, green, 0, green);

auto clipper = ClippingNode::create();
clipper->setAnchorPoint(Point(0.5, 0.5));
clipper->setPosition( Point(100, 100) );
clipper->setStencil(stencil);
clipper->setInverted(true);

// containerAddedAsChild->addChild(clipper, 20);      // this works fine
containerRenderedToTexture->addChild(clipper, 20);    // this breaks 

auto img = Sprite::create("test_sprite.png");
img->setAnchorPoint(Point(0.5, 0.5));
clipper->addChild(img);

如何让 ClippingNode 在 RenderTexture 上工作并获得预期结果(将 ClippingNode 添加为子节点而不是使用 RenderTexture 时得到的结果)?谢谢。

最佳答案

我不确定这是否正是您要问的,但您可以通过确保设置深度模板选项来让 ClippingNodes 正确渲染到您的 RenderTexture 上。

在 Cocos2d-x 3.x 中它看起来像这样:

RenderTexture* renderTexture = RenderTexture::create(paddedSize.width, paddedSize.height,
    Texture2D::PixelFormat::RGBA8888,
    GL_DEPTH24_STENCIL8_OES); // configure for clipping node

renderTexture->beginWithClear(0, 0, 0, 0, 1.0f);
clippingNode->Node::visit();
renderTexture->end();

在 Cocos2d-iPhone/Swift 3.x 中它看起来像这样:

CCRenderTexture *renderTexture = [CCRenderTexture renderTextureWithWidth:paddedSize.width height:paddedSize.height
    pixelFormat:CCTexturePixelFormat_RGBA8888
    depthStencilFormat:GL_DEPTH24_STENCIL8_OES];
[renderTexture beginWithClear:0.0f g:0.0f b:0.0f a:0.0f depth:1.0f];
[clippingNode visit];
[renderTexture end];

关于c++ - Cocos2d-x v3 : ClippingNode not working on RenderTexture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24867486/

相关文章:

c++ - 如何使用堆栈跟踪来确定崩溃原因?

c++ - 错误 C2511 - 未找到重载的成员函数

android - Android 设备的后退和主页按钮按下事件 (cocos2d-x 3)

c++ - Cocos2d-x 3.0 onTouchMoved 无法运行

ios - 如何添加滑动手势?

C++检查 vector 中一行中有多少个相同元素

c++ - boost::geometry::distance 使用 3D 基元编译错误

android - C++ 在 Android 上崩溃但在 iOS 上没有

c++ - (cocos2d-x 3.2/xcode 6) 如何打开 iOS 的 cpp-tests,没有项目文件

c++ - cocos2dx 3.3如何截取场景?