• cocos2d 重写顶点着色语言


    bool CCShaderSprite::initWithFile( const char *pszFilename )
    {
     bool ret=false;
     do
     {
       ret=CCSprite::initWithFile(pszFilename);
    //
       CCGLProgram* shader = new CCGLProgram();
       shader->initWithVertexShaderFilename("example_Water.vsh","example_Water.fsh");
       shader->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
       shader->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
       shader->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
       shader->link();
       shader->updateUniforms();
       
       m_uniformPos     = glGetUniformLocation(shader->getProgram(), "f_point");
       //m_uniformTime    = glGetUniformLocation(shader->getProgram(), "f_time");
       m_uniformMapHeight  = glGetUniformLocation(shader->getProgram(), "f_height");
       m_uniformMapWidth  = glGetUniformLocation(shader->getProgram(), "f_width");
       //m_uniformMonsterTex  = glGetUniformLocation(shader->getProgram(), "CC_Texture1");

       this->setShaderProgram(shader);
       shader->release();
       CHECK_GL_ERROR_DEBUG();


       CCSize size = CCDirector::sharedDirector()->getWinSize();
       m_Pos.x = size.width*0.5;
       m_Pos.y = size.height*0.5;


     } while (0);
     return ret;
    }

    void CCShaderSprite::draw( void )
    {
     //--you can set Uniform in here
      CC_NODE_DRAW_SETUP();
     
       //getShaderProgram()->setUniformLocationWith1i(m_uniformMonsterTex,1);
       getShaderProgram()->setUniformLocationWith1f(m_uniformMapHeight,sUniformMapHeight);
       getShaderProgram()->setUniformLocationWith1f(m_uniformMapWidth,sUniformMapWidth);
       getShaderProgram()->setUniformLocationWith2f(m_uniformPos,m_Pos.x,m_Pos.y);
       //getShaderProgram()->setUniformLocationWith1f(m_uniformTime,m_RippleTime);
     //ccGLBindTexture2DN(1,m_MonsterTexture->getName());

     CCSprite::draw();
    }

  • 相关阅读:
    WebRTC的一个例子
    Gerrit增加SSL证书
    Ruby on Rails 创建https应用
    使用Ruby来实现批量更新AD中字段
    pg gem 安装(postgresql94)
    Spark源码剖析(一):如何将spark源码导入到IDEA中
    Scala入门系列(十三):类型参数
    Scala入门系列(十二):隐式转换
    Scala 安装 Exception in thread "main" java.lang.VerifyError: Uninitialized object exists on backward branch 96
    Scala入门系列(十一):模式匹配
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6736800.html
Copyright © 2020-2023  润新知