Пример #1
0
bool ShaderMultiTexture::init()
{
    if (ShaderTestDemo::init())
    {
        auto s = Director::getInstance()->getWinSize();

        // Left: normal sprite
        auto left = Sprite::create("Images/grossinis_sister1.png");
        addChild(left);
        left->setPosition(s.width*1/4, s.height/2);

        // Right: normal sprite
        auto right = Sprite::create("Images/grossinis_sister2.png");
        addChild(right, 0, rightSpriteTag);
        right->setPosition(s.width*3/4, s.height/2);


        // Center: MultiTexture
        _sprite = Sprite::createWithTexture(left->getTexture());
        addChild(_sprite);
        _sprite->setPosition(Vec2(s.width/2, s.height/2));

        auto glprogram = GLProgram::createWithFilenames("Shaders/example_MultiTexture.vsh", "Shaders/example_MultiTexture.fsh");
        auto glprogramstate = GLProgramState::getOrCreateWithGLProgram(glprogram);
        _sprite->setGLProgramState(glprogramstate);

        glprogramstate->setUniformTexture("u_texture1", right->getTexture());
        glprogramstate->setUniformFloat("u_interpolate",0.5);

        // slider
        createSliderCtl();
        
        // menu
        auto label = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "change");
        auto mi = MenuItemLabel::create(label, CC_CALLBACK_1(ShaderMultiTexture::changeTexture, this));
        auto menu = Menu::create(mi, nullptr);
        addChild(menu);
        menu->setPosition(s.width * 7 / 8, s.height / 2);

        return true;
    }

    return false;
}
Пример #2
0
bool ShaderBlur::init()
{
    if( ShaderTestDemo::init() ) 
    {
        m_pBlurSprite = SpriteBlur::create("Images/grossini.png");

        CCSprite *sprite = CCSprite::create("Images/grossini.png");

        CCSize s = CCDirector::sharedDirector()->getWinSize();
        m_pBlurSprite->setPosition(ccp(s.width/3, s.height/2));
        sprite->setPosition(ccp(2*s.width/3, s.height/2));

        addChild(m_pBlurSprite);
        addChild(sprite);

        m_pSliderCtl = createSliderCtl();

        addChild(m_pSliderCtl);
        return true;
    }

    return false;
}