cocos2d-x v3.8でカスタムシェーダーを使おうとしています。

ボタンを押してmenuCallbackが呼ばれるたびに、_spriteが明るくなっていって  
最終的に真っ白に輝くようにしたいのですが、  
エラーが出てスプライトが明るくならず、ずっと黒いままです。

起動直後に出るエラーメッセージ  
libpng warning: iCCP: known incorrect sRGB profile

ボタンを押したときに出るメッセージ  
OpenGL error 0x0502 in
/Users/username/shadertest/cocos2d/cocos/renderer/CCFrameBuffer.cpp applyFBO
444

どうすれば明るさを変えられるようになるでしょうか。

HelloWorld.cpp

```

    bool HelloWorld::init()
    {
        if ( !Layer::init() )
        {
            return false;
        }
    
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
        /*中略*/
    
        _sprite = Sprite::createWithSpriteFrameName("RRGPlayer/walk/south/0001.png");
        _sprite->setPosition(visibleSize.width / 2 + origin.x,
                           visibleSize.height / 2 + origin.y);
        addChild(_sprite, 10);
    
        _glProgram = GLProgram::createWithFilenames("myshader.vsh", "myshader.fsh");
        CC_SAFE_RETAIN(_glProgram);
        _glProgram->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
        _glProgram->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
        _glProgram->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
        _glProgram->link();
        menuCallback(nullptr);
        _sprite->setGLProgram(_glProgram);
    
        return true;
    }
    
    
    void HelloWorld::menuCallback(Ref* pSender)
    {
        static float brightness = 0.0f;
        _glProgram->setUniformLocationWith1f(_glProgram->getUniformLocationForName("u_brightness"), brightness);
        _glProgram->updateUniforms();
    
        brightness += .1f;
        if (brightness > 2) {
            brightness = 0;
        }
    }
    
```

myshader.fsh

```

    varying vec4 v_fragmentColor;
    varying vec2 v_texCoord;
    
    uniform sampler2D u_texture;
    uniform float u_brightness;
    
    void main()
    {
        vec4 v_orColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);
        gl_FragColor = vec4(v_orColor.r * u_brightness,
                            v_orColor.g * u_brightness,
                            v_orColor.b * u_brightness,
                            v_orColor.a);
    }
    
```

myshader.vsh

```

    attribute vec4 a_position;
    attribute vec2 a_texCoord;
    attribute vec4 a_color;
    
    varying vec4 v_fragmentColor;
    varying vec2 v_texCoord;
    
    void main()
    {
        gl_Position = CC_PMatrix * a_position;
        v_fragmentColor = a_color;
        v_texCoord = a_texCoord;
    }
    
```
CC BY-SA 3.0
2015-10-10T05:47:37.700
17497
2016-09-29T15:05:24.040
8825
question
cocos2d-x opengl-es opengl
cocos2d-x v3.8のカスタムシェーダーで、あとからsetUniformLocationで変更を反映する
GLProgramStateを使ってできました。

```

    bool HelloWorld::init()
    {
        if ( !Layer::init() )
        {
            return false;
        }
    
        /*中略*/
    
        _sprite = Sprite::createWithSpriteFrameName("RRGPlayer/walk/south/0001.png");
        _sprite->setPosition(visibleSize.width / 2 + origin.x,
                           visibleSize.height / 2 + origin.y);
        addChild(_sprite, 10);
    
        GLProgram* glProgram = GLProgram::createWithFilenames("myshader.vsh", "myshader.fsh");
        GLProgramState* state = GLProgramState::getOrCreateWithGLProgram(glProgram);
        _sprite->setGLProgramState(state);
    
        return true;
    }
    
    
    void HelloWorld::menuCloseCallback(Ref* pSender)
    {
        static float brightness = 0.0f;
        GLProgramState* state = _sprite->getGLProgramState();
        state->setUniformFloat("u_brightness", brightness);
    
        brightness += .1f;
        if (brightness > 2) {
            brightness = 0;
        }
    }
    
```
CC BY-SA 3.0
2015-10-11T08:48:12.523
17530
2015-10-11T08:48:12.523
8825
17497
answer