原文地址:http://www.cnblogs.com/icethawless/archive/2013/05/16/3082004.html
ocos2d-x v2.1.3 模板缓冲区的清空有问题,当应用了模板测试的节点移动或者缩放时,就能看出来,有明显的拖影,裁剪区域和预设的不一致。
网上搜了一下,看到cocos2d-iphone版本已经给出了解决方案,需要改一下CCClippingNode.cpp,可能是cocos2dx这边还没有同步吧:
https://github.com/cocos2d/cocos2d-iphone/commit/b02c8a8686620cfc932b90c8e1ff78d9fcbe205a
修改后代码:
///
// CLEAR STENCIL BUFFER
// manually clear the stencil buffer by drawing a fullscreen rectangle on it
// setup the stencil test func like this:
// for each pixel in the fullscreen rectangle
// never draw it into the frame buffer
// if not in inverted mode: set the current layer value to 0 in the stencil buffer
// if in inverted mode: set the current layer value to 1 in the stencil buffer
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
glClearStencil(!m_bInverted ? 0 : ~0);
glStencilOp(!m_bInverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP);
// draw a fullscreen solid rectangle to clear the stencil buffer
//ccDrawSolidRect(CCPointZero, ccpFromSize([[CCDirector sharedDirector] winSize]), ccc4f(1, 1, 1, 1));
ccDrawSolidRect(CCPointZero, ccpFromSize(CCDirector::sharedDirector()->getWinSize()), ccc4f(1, 1, 1, 1));
glClear(GL_STENCIL_BUFFER_BIT);