zoukankan      html  css  js  c++  java
  • 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();
    }

  • 相关阅读:
    文本框字数减少
    区分兼容IE6/IE7/IE8/IE9/FF的CSS HACK写法
    将浏览器兼容代码标明信息并相互分开
    JavaScript正则表达式
    CSS3 @font-face
    iOS 获取手机的使用存储信息
    升级 ox 10.11的系统以后执行 pod install 的时候报错
    Xcode7安装模拟器
    iOS-视图生命周期
    Xcode升级插件失效修复快捷方式
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6736799.html
Copyright © 2011-2022 走看看