本文整理汇总了C++中CCGLProgram::initWithVertexShaderFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ CCGLProgram::initWithVertexShaderFilename方法的具体用法?C++ CCGLProgram::initWithVertexShaderFilename怎么用?C++ CCGLProgram::initWithVertexShaderFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCGLProgram
的用法示例。
在下文中一共展示了CCGLProgram::initWithVertexShaderFilename方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadCustomShaders
bool Assets::loadCustomShaders()
{
/// Scrollable texture shader
{
CCGLProgram *shader = new CCGLProgram();
shader->initWithVertexShaderFilename("shaders/shader_PositionTexture_uColor_uTime.vsh", "shaders/shader_PositionTexture_uColor_uTime.fsh");
shader->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
shader->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
shader->link();
shader->updateUniforms();
CCShaderCache::sharedShaderCache()->addProgram(shader, settings::kShader_PositionTexture_uColor_uTime);
}
/// Grayscale shader
{
CCGLProgram *shader = new CCGLProgram();
shader->initWithVertexShaderFilename("shaders/shader_Grayscale.vsh", "shaders/shader_Grayscale.fsh");
shader->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
shader->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
shader->link();
shader->updateUniforms();
CCShaderCache::sharedShaderCache()->addProgram(shader, settings::kShader_Grayscale);
}
CHECK_GL_ERROR_DEBUG();
return true;
}
示例2: loadShader
CCGLProgram* CCWaveFilter::loadShader()
{
CCGLProgram* program = new CCGLProgram();
program->initWithVertexShaderFilename("wave.vsh","wave.fsh");
return program;
}
示例3: loadShaderVertex
void ShaderNode::loadShaderVertex(const char *vert, const char *frag)
{
CCGLProgram* shader = new CCGLProgram();
shader->initWithVertexShaderFilename(vert, frag); //载入着色器程序
//绑定attribute变量
shader->addAttribute("a_position", 0);
shader->addAttribute("a_color", 1);
shader->link();
//获取attribute变量标识
m_attributeColor = glGetAttribLocation(shader->getProgram(), "a_color");
m_attributePosition = glGetAttribLocation(
shader->getProgram(), "a_position");
shader->updateUniforms();
//获取uniform变量标识
m_uniformResolution = glGetUniformLocation(shader->getProgram(), "resolution");
m_uniformTime = glGetUniformLocation(shader->getProgram(), "time");
m_uniformTex0 = glGetUniformLocation(shader->getProgram(), "tex0");
//使用着色器程序
this->setShaderProgram(shader);
shader->release();
}
示例4:
static int tolua_CCGLProgram_CCGLProgram_initWithVertexShaderFilename00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CCGLProgram",0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
!tolua_isstring(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
CCGLProgram* self = (CCGLProgram*) tolua_tousertype(tolua_S,1,0);
const char* vShaderFilename = ((const char*) tolua_tostring(tolua_S,2,0));
const char* fShaderFilename = ((const char*) tolua_tostring(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'initWithVertexShaderFilename'", NULL);
#endif
{
bool tolua_ret = (bool) self->initWithVertexShaderFilename(vShaderFilename,fShaderFilename);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'initWithVertexShaderFilename'.",&tolua_err);
return 0;
#endif
}
示例5: reloadCustomShaders
bool Assets::reloadCustomShaders()
{
CCLOG("reload custom shaders");
CCGLProgram *shader = CCShaderCache::sharedShaderCache()->programForKey(settings::kShader_PositionTexture_uColor_uTime);
shader->reset();
shader->initWithVertexShaderFilename("shaders/shader_PositionTexture_uColor_uTime.vsh", "shaders/shader_PositionTexture_uColor_uTime.fsh");
shader->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
shader->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
shader->link();
shader->updateUniforms();
/// TODO
CHECK_GL_ERROR_DEBUG();
return true;
}
示例6: loadShaderVertex
void ShaderNode::loadShaderVertex(const char *vert, const char *frag)
{
CCGLProgram *shader = new CCGLProgram();
shader->initWithVertexShaderFilename(vert, frag);
shader->addAttribute("aVertex", kCCVertexAttrib_Position);
shader->link();
shader->updateUniforms();
m_uniformCenter = glGetUniformLocation(shader->getProgram(), "center");
m_uniformResolution = glGetUniformLocation(shader->getProgram(), "resolution");
m_uniformTime = glGetUniformLocation(shader->getProgram(), "time");
this->setShaderProgram(shader);
shader->release();
}
示例7: init
// on "init" you need to initialize your instance
bool Stage::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayer::init());
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// Get window size and place the label upper.
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* pBgSprite;
// 3. Add add a splash screen, show the cocos2d splash image.
pBgSprite = CCSprite::create("bg.jpg");
CC_BREAK_IF(! pBgSprite);
// Place the sprite on the center of the screen
pBgSprite->setPosition(ccp(size.width/2, size.height/2));
// Add the sprite to HelloWorld layer as a child layer.
this->addChild(pBgSprite, -5);
//game logo
CCSprite* pLogoSprite;
// 3. Add add a splash screen, show the cocos2d splash image.
pLogoSprite = CCSprite::create("glogo.png");
CC_BREAK_IF(! pLogoSprite);
// Place the sprite on the center of the screen
pLogoSprite->setAnchorPoint(ccp(0.0f, 01.f));
pLogoSprite->setPosition(ccp(0, size.height));
// Add the sprite to HelloWorld layer as a child layer.
this->addChild(pLogoSprite, -4);
CCSprite* pBottleSprite = CCSprite::create("bottle.png");
CC_BREAK_IF(! pBottleSprite);
pBottleSprite->setAnchorPoint(ccp(0.0f, 0.0f));
// Place the sprite on the center of the screen
pBottleSprite->setPosition(ccp(0.0f, 0.0f));
// Add the sprite to HelloWorld layer as a child layer.
this->addChild(pBottleSprite, 4);
SetupWorld();
/*
sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Flower.vsh", "Shaders/example_Flower.fsh");
sn->setPosition(ccp(size.width/2, size.height/2));
addChild(sn, -1);
*/
rTexture = CCRenderTexture::create(WIN_WIDTH, WIN_HEIGHT,(CCTexture2DPixelFormat)kTexture2DPixelFormat_RGBA4444);
gTexture = CCRenderTexture::create(WIN_WIDTH, WIN_HEIGHT,(CCTexture2DPixelFormat)kTexture2DPixelFormat_RGBA4444);
bTexture = CCRenderTexture::create(WIN_WIDTH, WIN_HEIGHT,(CCTexture2DPixelFormat)kTexture2DPixelFormat_RGBA4444);
yTexture = CCRenderTexture::create(WIN_WIDTH, WIN_HEIGHT,(CCTexture2DPixelFormat)kTexture2DPixelFormat_RGBA4444);
if (NULL == rTexture)
{
CCLog("create renderTex fail");
return false;
}
mainTexture = CCRenderTexture::create(WIN_WIDTH, WIN_HEIGHT, (CCTexture2DPixelFormat)kTexture2DPixelFormat_RGBA4444);
if (NULL == mainTexture)
{
CCLog("create mainTexture fail");
return false;
}
///
//renderTexture.sprite.shaderProgram = [[CCGLProgram alloc] initWithVertexShaderByteArray:ccPositionTextureA8Color_vert
//fragmentShaderByteArray:ccPositionTextureColorAlphaTest_frag];
shader = new CCGLProgram();
//shader->initWithVertexShaderByteArray(ccPositionTextureA8Color_vert, ccPositionTextureColorAlphaTest_frag);
shader->initWithVertexShaderFilename("Shaders/mix.vsh", "Shaders/mix.fsh");
rTexture->getSprite()->setShaderProgram(shader);
gTexture->getSprite()->setShaderProgram(shader);
bTexture->getSprite()->setShaderProgram(shader);
yTexture->getSprite()->setShaderProgram(shader);
shader->release();
//[renderTexture.sprite.shaderProgram addAttribute:kCCAttributeNamePosition index:kCCVertexAttrib_Position];
shader->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
//[renderTexture.sprite.shaderProgram addAttribute:kCCAttributeNameColor index:kCCVertexAttrib_Color];
shader->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
//[renderTexture.sprite.shaderProgram addAttribute:kCCAttributeNameTexCoord index:kCCVertexAttrib_TexCoords];
shader->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
shader->link();
shader->updateUniforms();
alphaValueLocation = glGetUniformLocation(shader->getProgram(), "u_alpha_value");
colorValueLocation = glGetUniformLocation(shader->getProgram(), "u_color_value");
//m_uMaskLocation = glGetUniformLocation( shader->getProgram(), "u_mask");
shader->setUniformLocationWith1f(alphaValueLocation, THROLD);
shader->use();
//.........这里部分代码省略.........