cocos2d-x CCClippingNode 专题

1.CCClippingNode在部分android上不起作用需要修改src\org\cocos2dx\lib\Cocos2dxGLSurfaceView.java

//from
public Cocos2dxGLSurfaceView onCreateView() {
  return new Cocos2dxGLSurfaceView(this);
}

//to
public Cocos2dxGLSurfaceView onCreateView() {
  Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
  glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
  return glSurfaceView;
}

 

2.参考cocos2d-x 3.x的写法,做如下修改。

//cocos2dx/misc_nodes/CCClippingNode.cpp

if (m_fAlphaThreshold < 1) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
  // manually save the alpha test state
  currentAlphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
  glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *)&currentAlphaTestFunc);
  glGetFloatv(GL_ALPHA_TEST_REF, &currentAlphaTestRef);
  // enable alpha testing
  glEnable(GL_ALPHA_TEST);
  // check for OpenGL error while enabling alpha test
  CHECK_GL_ERROR_DEBUG();
  // pixel will be drawn only if greater than an alpha threshold
  glAlphaFunc(GL_GREATER, m_fAlphaThreshold);
#else
  // since glAlphaTest do not exists in OES, use a shader that writes
  // pixel only if greater than an alpha threshold
  CCGLProgram *program = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColorAlphaTest);
  GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), kCCUniformAlphaTestValue);
  // set our alphaThreshold
  program->use();// change by ix 2014-6-10 glUseProgram()将OpenGL渲染管道切换到着色器模式
  program->setUniformLocationWith1f(alphaValueLocation, m_fAlphaThreshold);
  // we need to recursively apply this shader to all the nodes in the stencil node
  // XXX: we should have a way to apply shader to all nodes without having to do this
  setProgram(m_pStencil, program);
#endif
}

 

参考:

http://blog.csdn.net/honghaier/article/details/8858743

posted on 2014-06-08 20:00  the seal  阅读(425)  评论(0编辑  收藏  举报