本文整理汇总了C++中setShaderProgram函数的典型用法代码示例。如果您正苦于以下问题:C++ setShaderProgram函数的具体用法?C++ setShaderProgram怎么用?C++ setShaderProgram使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setShaderProgram函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void Label::updateShaderProgram()
{
switch (_currLabelEffect)
{
case cocos2d::LabelEffect::NORMAL:
if (_useDistanceField)
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL));
else if (_useA8Shader)
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_NORMAL));
else
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
break;
case cocos2d::LabelEffect::OUTLINE:
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_OUTLINE));
_uniformEffectColor = glGetUniformLocation(_shaderProgram->getProgram(), "v_effectColor");
break;
case cocos2d::LabelEffect::GLOW:
if (_useDistanceField)
{
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW));
_uniformEffectColor = glGetUniformLocation(_shaderProgram->getProgram(), "v_effectColor");
}
break;
default:
return;
}
_uniformTextColor = glGetUniformLocation(_shaderProgram->getProgram(), "v_textColor");
}
示例2: switch
void Label::setLabelEffect(LabelEffect effect,const Color3B& effectColor)
{
if(_useDistanceField == false)
return;
_currLabelEffect = effect;
_effectColor = effectColor;
switch (_currLabelEffect)
{
case cocos2d::LabelEffect::NORMAL:
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL));
break;
case cocos2d::LabelEffect::OUTLINE:
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE));
break;
case cocos2d::LabelEffect::SHADOW:
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW));
break;
case cocos2d::LabelEffect::GLOW:
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW));
break;
default:
return;
}
_uniformEffectColor = glGetUniformLocation(_shaderProgram->getProgram(), "v_effectColor");
}
示例3: memset
// designated initializer
bool CC3DSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated)
{
if (CCNode::init())
{
// clean the Quad
memset(&m_sQuad, 0, sizeof(m_sQuad));
// Atlas: Color
ccColor4B tmpColor = { 255, 255, 255, 255 };
m_sQuad.bl.colors = tmpColor;
m_sQuad.br.colors = tmpColor;
m_sQuad.tl.colors = tmpColor;
m_sQuad.tr.colors = tmpColor;
// shader program
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
//set texture
setTexture(pTexture);
//set textureRect
setTextureRect(rect, rotated);
return true;
}
else
{
return false;
}
}
示例4: setShaderProgram
bool BatchNode::init()
{
bool ret = Node::init();
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
return ret;
}
示例5: CCTextureAtlas
//
// init with CCTexture2D
//
KDbool CCSpriteBatchNode::initWithTexture ( CCTexture2D* pTexture, KDuint uCapacity )
{
m_tBlendFunc.src = CC_BLEND_SRC;
m_tBlendFunc.dst = CC_BLEND_DST;
m_pTextureAtlas = new CCTextureAtlas ( );
if ( 0 == uCapacity )
{
uCapacity = kDefaultSpriteBatchCapacity;
}
m_pTextureAtlas->initWithTexture ( pTexture, uCapacity );
updateBlendFunc ( );
// no lazy alloc in this node
m_pChildren = new CCArray ( );
m_pChildren->initWithCapacity ( uCapacity );
m_pDescendants = new CCArray ( );
m_pDescendants->initWithCapacity ( uCapacity );
setShaderProgram ( CCShaderCache::sharedShaderCache ( )->programForKey ( kCCShader_PositionTextureColor ) );
return KD_TRUE;
}
示例6: propertyNamed
void CCTMXLayer::parseInternalProperties()
{
// if cc_vertex=automatic, then tiles will be rendered using vertexz
CCString *vertexz = propertyNamed("cc_vertexz");
if (vertexz)
{
// If "automatic" is on, then parse the "cc_alpha_func" too
if (vertexz->m_sString == "automatic")
{
m_bUseAutomaticVertexZ = true;
CCString *alphaFuncVal = propertyNamed("cc_alpha_func");
float alphaFuncValue = 0.0f;
if (alphaFuncVal != NULL)
{
alphaFuncValue = alphaFuncVal->floatValue();
}
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColorAlphaTest));
GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), kCCUniformAlphaTestValue);
getShaderProgram()->use();
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
getShaderProgram()->setUniformLocationWith1f(alphaValueLocation, alphaFuncValue);
CHECK_GL_ERROR_DEBUG();
}
else
{
m_nVertexZvalue = vertexz->intValue();
}
}
}
示例7: CCGLProgram
void SpriteBlur::initProgram()
{
GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile(
CCFileUtils::sharedFileUtils()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString();
CCGLProgram* pProgram = new CCGLProgram();
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource);
setShaderProgram(pProgram);
pProgram->release();
CHECK_GL_ERROR_DEBUG();
getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
CHECK_GL_ERROR_DEBUG();
getShaderProgram()->link();
CHECK_GL_ERROR_DEBUG();
getShaderProgram()->updateUniforms();
CHECK_GL_ERROR_DEBUG();
subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract");
blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize");
CHECK_GL_ERROR_DEBUG();
}
示例8: setShaderProgram
bool BloodFlashSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect)
{
if (CCSprite::initWithTexture(pTexture, rect))
{
CCGLProgram *program = new CCGLProgram;
GLchar *fragSrc = (GLchar *)CCString::createWithContentsOfFile(
CCFileUtils::sharedFileUtils()->fullPathForFilename(_fragShaderName.c_str()).c_str())->getCString();
program->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSrc);
setShaderProgram(program);
program->release();
CHECK_GL_ERROR_DEBUG();
getShaderProgram()->link();
CHECK_GL_ERROR_DEBUG();
getShaderProgram()->updateUniforms();
CHECK_GL_ERROR_DEBUG();
return true;
}
return false;
}
示例9: setTouchEnabled
bool CColorView::initWithColor(const Color4B& color)
{
setTouchEnabled(false);
_displayedColor.r = _realColor.r = color.r;
_displayedColor.g = _realColor.g = color.g;
_displayedColor.b = _realColor.b = color.b;
_displayedOpacity = _realOpacity = color.a;
_cascadeOpacityEnabled = false;
_cascadeColorEnabled = false;
m_tBlendFunc.src = GL_SRC_ALPHA;
m_tBlendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
for (size_t i = 0; i < sizeof(m_pSquareVertices) / sizeof( m_pSquareVertices[0]); i++ )
{
m_pSquareVertices[i].x = 0.0f;
m_pSquareVertices[i].y = 0.0f;
}
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_COLOR));
setAnchorPoint(CCWIDGET_BASIC_DEFAULT_ANCHOR_POINT);
setContentSize(CCWIDGET_BASIC_DEFAULT_CONTENT_SIZE);
updateColor();
return true;
}
示例10: CCASSERT
/*
* init with Texture2D
*/
bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity)
{
CCASSERT(capacity>=0, "Capacity must be >= 0");
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
_textureAtlas = new TextureAtlas();
if (0 == capacity)
{
capacity = kDefaultSpriteBatchCapacity;
}
_textureAtlas->initWithTexture(tex, capacity);
updateBlendFunc();
// no lazy alloc in this node
_children = new Array();
_children->initWithCapacity(capacity);
_descendants = new Array();
_descendants->initWithCapacity(capacity);
setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
return true;
}
示例11: tryLoadSpriteSheet
bool CCSuperAnim::Init(const std::string& theAbsAnimFile, int theId, CCSuperAnimListener *theListener)
{
// try to load the sprite sheet file
mSpriteSheetFileFullPath = theAbsAnimFile.substr(0, theAbsAnimFile.find_last_of('.') + 1) + "plist";
tryLoadSpriteSheet();
mAnimHandler = GetSuperAnimHandler(theAbsAnimFile);
if (!mAnimHandler.IsValid())
{
char aBuffer[256];
sprintf(aBuffer, "Can't load the SuperAnim %s.", theAbsAnimFile.c_str());
CCMessageBox(aBuffer, "Error");
return false;
}
setContentSize(CC_SIZE_PIXELS_TO_POINTS(CCSizeMake(mAnimHandler.mWidth, mAnimHandler.mHeight)));
mId = theId;
mListener = theListener;
mAnimState = kAnimStateInitialized;
mIsFlipX = mIsFlipY = false;
mSpeedFactor = 1.0f;
mIsLoop = false;
// shader program
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
scheduleUpdate();
setAnchorPoint(ccp(0.5f, 0.5f));
return true;
}
示例12: CC_BREAK_IF
bool Terrain::init(b2World* world,Hero* hero)
{
bool bRet = true;
do
{
CC_BREAK_IF(!CCNode::init());
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture));
_world = world;
_sceenSize = CCDirector::sharedDirector()->getWinSize();
//初始点
_lastHillKeyPoint = CCPointMake(0,_sceenSize.height*CONST_OFFSET_Y);
_stripes = CCSprite::create("stripe.png");
//_stripes = createStripe();
ccTexParams tp2 = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE};
_stripes->getTexture()->setTexParameters(&tp2);
_stripes->retain();
//hero
_hero = hero;
addChild(_hero,11);
bRet = true;
} while (0);
return bRet;
}
示例13: CCTextureAtlas
bool CCAtlasNode::initWithTexture(CCTexture2D* texture, unsigned int tileWidth, unsigned int tileHeight,
unsigned int itemsToRender)
{
m_uItemWidth = tileWidth;
m_uItemHeight = tileHeight;
m_tColorUnmodified = ccWHITE;
//m_bIsOpacityModifyRGB = true;
m_tBlendFunc.src = CC_BLEND_SRC;
m_tBlendFunc.dst = CC_BLEND_DST;
m_pTextureAtlas = new CCTextureAtlas();
m_pTextureAtlas->initWithTexture(texture, itemsToRender);
if (! m_pTextureAtlas)
{
CCLOG("cocos2d: Could not initialize CCAtlasNode. Invalid Texture.");
return false;
}
this->updateBlendFunc();
this->updateOpacityModifyRGB();
this->calculateMaxItems();
m_uQuadsToDraw = itemsToRender;
// shader stuff
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");
return true;
}
示例14: TextureAtlas
bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender)
{
_itemWidth = tileWidth;
_itemHeight = tileHeight;
_colorUnmodified = Color3B::WHITE;
_isOpacityModifyRGB = true;
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
_textureAtlas = new TextureAtlas();
_textureAtlas->initWithTexture(texture, itemsToRender);
if (! _textureAtlas)
{
CCLOG("cocos2d: Could not initialize AtlasNode. Invalid Texture.");
return false;
}
this->updateBlendFunc();
this->updateOpacityModifyRGB();
this->calculateMaxItems();
_quadsToDraw = itemsToRender;
// shader stuff
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR));
_uniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");
return true;
}
示例15: GLProgram
void ShaderSprite::initShader()
{
GLchar * fragSource = (GLchar*) String::createWithContentsOfFile(
FileUtils::getInstance()->fullPathForFilename(_fragSourceFile).c_str())->getCString();
auto program = new GLProgram();
program->initWithByteArrays(ccPositionTextureColor_vert, fragSource);
setShaderProgram(program);
program->release();
CHECK_GL_ERROR_DEBUG();
program->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
program->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
program->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
CHECK_GL_ERROR_DEBUG();
program->link();
CHECK_GL_ERROR_DEBUG();
program->updateUniforms();
CHECK_GL_ERROR_DEBUG();
buildCustomUniforms();
CHECK_GL_ERROR_DEBUG();
}