【发布时间】:2014-02-26 13:15:28
【问题描述】:
目前我正在使用 Cocos2d 中的着色器。我的目标是将着色器应用于整个屏幕(一个节点及其子节点除外),以便在游戏模糊时有一个覆盖菜单。
现在我发现 this tutorial 可以在 cocos2D 中使用着色器,结果如下代码
CCSprite *aSprite = [CCSprite spriteWithImageNamed:@"Default.png"];
aSprite.contentSizeType = CCSizeTypeNormalized;
aSprite.contentSize = CGSizeMake(0.5,0.5);
NSString *fullPath = [[NSBundle mainBundle] pathForResource:@"CSEEmboss" ofType:@"fsh"];
const GLchar * fragmentSource = (GLchar*) [[NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil] UTF8String];
aSprite.shaderProgram = [[CCGLProgram alloc] initWithVertexShaderByteArray:ccPositionTextureA8Color_vert
fragmentShaderByteArray:fragmentSource];
[aSprite.shaderProgram addAttribute:kCCAttributeNamePosition index:kCCVertexAttrib_Position];
[aSprite.shaderProgram addAttribute:kCCAttributeNameTexCoord index:kCCVertexAttrib_TexCoords];
[aSprite.shaderProgram link];
[aSprite.shaderProgram updateUniforms];
[aSprite.shaderProgram use];
[self.scene addChild:aSprite];
这确实将浮雕应用于精灵,但是当我将孩子添加到该精灵时,着色器并未应用在那里,我应该怎么做?我的场景包含许多孩子,并且对每个孩子都使用循环添加和删除着色器似乎不太合适。
【问题讨论】:
标签: ios opengl-es cocos2d-iphone shader