先上图吧。使用opengl前后的对比:
1.在cpp中使用openGL shader。
(1)添加gray.vsh和gray.fsh到资源目录(见附件)。(2)添加如下代码:
- boolHelloWorld::init()
- {
- if(!Layer::init())
- returnfalse;
- }
- izevisibleSize=Director::getInstance()->getVisibleSize();
- autosprite=Sprite::create("HelloWorld.png");
- sprite->setAnchorPoint(Point(0.5,0.5));
- sprite->setPosition(Point(visibleSize.width/3,visibleSize.height/3));
- this->addChild(sprite);
- graySprite(sprite);
- true;
- voidHelloWorld::graySprite(Sprite*sprite)
- {
- if(sprite)
- GLProgram*p=newGLProgram();
- p->initWithFilenames("gray.vsh","gray.fsh");
- p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION,GLProgram::VERTEX_ATTRIB_POSITION);
- p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR,GLProgram::VERTEX_ATTRIB_COLOR);
- p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD,GLProgram::VERTEX_ATTRIB_TEX_COORDS);
- p->link();
- p->updateUniforms();
- sprite->setShaderProgram(p);
- }
2.在js中使用opengl shader.
(1)添加gray.vsh和gray.fsh到资源目录。(2)添加如下代码: