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"); }
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"); }
// 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; } }
bool BatchNode::init() { bool ret = Node::init(); setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return ret; }
// // 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; }
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(); } } }
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(); }
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; }
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; }
/* * 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; }
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; }
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; }
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; }
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; }
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(); }
bool BlurNode::init() { if (!Node::init()) return false; // read and add my shader GLProgram* program = GLProgram::createWithFilenames("ccShader_blur.vert", "BlurNormal.frag"); if (!program) return false; setShaderProgram(program); // get uniform variable location _uSolutionLocation = program->getUniformLocation("u_resolution"); // load texture2D _texture = TextureCache::getInstance()->addImage("cballs.png"); if (!_texture) return false; _texture->retain(); setContentSize(_texture->getContentSize()); Size size = getContentSize(); // init vertices array and texCoord array _vertices.push_back(Point::ZERO); _vertices.push_back(Point(size.width, 0)); _vertices.push_back(Point(0, size.height)); _vertices.push_back(Point(size.width, size.height)); _texCoord.push_back(Point(0, 1)); _texCoord.push_back(Point(1, 1)); _texCoord.push_back(Point::ZERO); _texCoord.push_back(Point(1, 0)); scheduleUpdate(); return true; }
NS_CC_BEGIN //implementation CCParticleSystemQuad // overriding the init method bool CCParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles) { // base initialization if( CCParticleSystem::initWithTotalParticles(numberOfParticles) ) { // allocating data space if( ! this->allocMemory() ) { this->release(); return false; } setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); // Need to listen the event only when not use batchnode, because it will use VBO CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CCParticleSystemQuad::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); return true; } return false; }
// 初始化方法,用纹理 bool CCSpriteBatchNode::initWithTexture(CCTexture2D *tex, unsigned int capacity) { m_blendFunc.src = CC_BLEND_SRC; m_blendFunc.dst = CC_BLEND_DST; m_pobTextureAtlas = new CCTextureAtlas(); if (0 == capacity) { capacity = kDefaultSpriteBatchCapacity; } m_pobTextureAtlas->initWithTexture(tex, capacity); updateBlendFunc(); // no lazy alloc in this node m_pChildren = new CCArray(); m_pChildren->initWithCapacity(capacity); m_pobDescendants = new CCArray(); m_pobDescendants->initWithCapacity(capacity); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); return true; }
NS_CC_BEGIN CCCatmullRomSprite::CCCatmullRomSprite(CCSprite* sprite) : m_sprite(NULL), m_dirty(false), m_allVisible(true), m_tension(0.1f), m_atlas(NULL) { CCAssert(sprite != NULL, "CCCatmullRomSprite doesn't accept NULL sprite"); // save sprite m_sprite = sprite; CC_SAFE_RETAIN(m_sprite); // atlas m_atlas = CCTextureAtlasEx::createWithTexture(m_sprite->getTexture(), kDefaultSpriteBatchCapacity); CC_SAFE_RETAIN(m_atlas); // shader program setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); // set content size setContentSize(CCSizeZero); // update some member variables m_patternLength = m_sprite->getContentSize().width; m_patternWidth = m_sprite->getContentSize().height; }
bool LayerColor::initWithColor(const Color4B& color, GLfloat w, GLfloat h) { if (Layer::init()) { // default blend function _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; _displayedColor.r = _realColor.r = color.r; _displayedColor.g = _realColor.g = color.g; _displayedColor.b = _realColor.b = color.b; _displayedOpacity = _realOpacity = color.a; for (size_t i = 0; i<sizeof(_squareVertices) / sizeof( _squareVertices[0]); i++ ) { _squareVertices[i].x = 0.0f; _squareVertices[i].y = 0.0f; } updateColor(); setContentSize(Size(w, h)); setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP)); return true; } return false; }
bool CCSpriteBatchNode::initWithTexture(CCTexture2D *tex, unsigned int capacity) { //设置混合系数,源混合系数为CC_BLEND_SRC,目标混合系数为CC_BLEND_DST, // 则图像绘制时按照纹理或色彩的Alpha值与背景进行混合。 m_blendFunc.src = CC_BLEND_SRC; m_blendFunc.dst = CC_BLEND_DST; //创建一个图片集管理器 m_pobTextureAtlas = new CCTextureAtlas(); /// 如果容量为0,则表示容量默认为29 if (0 == capacity) { capacity = kDefaultSpriteBatchCapacity; } //将纹理和图块数量做为参数初始化图片集,这里可知图块集还是依靠CCTextureAtlas类。 m_pobTextureAtlas->initWithTexture(tex, capacity); //更新混合状态 updateBlendFunc(); // no lazy alloc in this node// 新建一个CCArray实例,将m_pChildren指向它 m_pChildren = new CCArray(); m_pChildren->initWithCapacity(capacity); m_pobDescendants = new CCArray(); m_pobDescendants->initWithCapacity(capacity); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); return true; }
void DynamicBackground::initProgram() { std::string sharderStr = CCFileUtils::getInstance()->fullPathForFilename("Shaders/shader_dynamic_bg.fsh"); GLchar * fragSource = (GLchar*)CCString::createWithContentsOfFile(sharderStr.c_str())->getCString(); sharderStr = CCFileUtils::getInstance()->fullPathForFilename("Shaders/shader_very_pos_color.vsh"); GLchar * vertexSource = (GLchar*)CCString::createWithContentsOfFile(sharderStr.c_str())->getCString(); CCGLProgram* pProgram = new CCGLProgram(); pProgram->initWithVertexShaderByteArray(vertexSource, 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(); _bgLocation = glGetUniformLocation(getShaderProgram()->getProgram(), "u_bg_texture"); _bgSize = glGetUniformLocation(getShaderProgram()->getProgram(), "u_bg_size"); _bgTextureCoordOffset = glGetUniformLocation(getShaderProgram()->getProgram(), "u_bg_CoordOffset"); CHECK_GL_ERROR_DEBUG(); }
void SpriteMask::initProgram() { std::string sharderStr = CCFileUtils::getInstance()->fullPathForFilename("Shaders/shader_mask.fsh"); GLchar * fragSource = (GLchar*)CCString::createWithContentsOfFile(sharderStr.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(); _maskLocation = glGetUniformLocation(getShaderProgram()->getProgram(), "u_mask"); _offsetLocation = glGetUniformLocation(getShaderProgram()->getProgram(), "v_offset"); CHECK_GL_ERROR_DEBUG(); }
void TMXLayer::parseInternalProperties() { // if cc_vertex=automatic, then tiles will be rendered using vertexz String *vertexz = getProperty("cc_vertexz"); if (vertexz) { // If "automatic" is on, then parse the "cc_alpha_func" too if (vertexz->m_sString == "automatic") { m_bUseAutomaticVertexZ = true; String *alphaFuncVal = getProperty("cc_alpha_func"); float alphaFuncValue = 0.0f; if (alphaFuncVal != NULL) { alphaFuncValue = alphaFuncVal->floatValue(); } setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST)); GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE); // NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison // use shader program to set uniform getShaderProgram()->use(); getShaderProgram()->setUniformLocationWith1f(alphaValueLocation, alphaFuncValue); CHECK_GL_ERROR_DEBUG(); } else { m_nVertexZvalue = vertexz->intValue(); } } }
KDbool CCAtlasNode::initWithTexture ( CCTexture2D* pTexture, KDuint uTileWidth, KDuint uTileHeight, KDuint uItemsToRender ) { m_uItemWidth = uTileWidth; m_uItemHeight = uTileHeight; m_tColorUnmodified = ccWHITE; m_bIsOpacityModifyRGB = KD_TRUE; m_tBlendFunc.src = CC_BLEND_SRC; m_tBlendFunc.dst = CC_BLEND_DST; m_pTextureAtlas = new CCTextureAtlas ( ); m_pTextureAtlas->initWithTexture ( pTexture, uItemsToRender ); if ( !m_pTextureAtlas ) { CCLOG ( "XCocos2D : Could not initialize CCAtlasNode. Invalid Texture."); return KD_FALSE; } this->updateBlendFunc ( ); this->updateOpacityModifyRGB ( ); this->calculateMaxItems ( ); m_uQuadsToDraw = uItemsToRender; // shader stuff setShaderProgram ( CCShaderCache::sharedShaderCache ( )->programForKey ( kCCShader_PositionTexture_uColor ) ); #if defined ( USE_OPEN_GLES2 ) m_nUniformColor = glGetUniformLocation ( getShaderProgram ( )->getProgram ( ), "u_color" ); #endif return KD_TRUE; }
bool CCLayerColor::initWithColor(const ccColor4B& color, GLfloat w, GLfloat h) { if( CCLayer::init() ) { // default blend function m_tBlendFunc.src = GL_SRC_ALPHA; m_tBlendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; m_tColor.r = color.r; m_tColor.g = color.g; m_tColor.b = color.b; m_cOpacity = color.a; for (int i = 0; i<sizeof(m_pSquareVertices) / sizeof( m_pSquareVertices[0]); i++ ) { m_pSquareVertices[i].x = 0.0f; m_pSquareVertices[i].y = 0.0f; } updateColor(); setContentSize(CCSizeMake(w, h)); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor)); } return true; }
bool CCSprite3D::init() { CCGLProgram* program = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture); setShaderProgram(program); return true; }
kore::ShaderProgramPass::ShaderProgramPass(ShaderProgram* prog) : _program(NULL), _executionType(EXECUTE_REPEATING), _executed(false), _timerQuery(0), _useGPUProfiling(false), _name("UNNAMED PASS") { setShaderProgram(prog); }
void CCMenuItemColor::initWithColorAndTarget(ccColor4B normal, ccColor4B selected, ccColor4B focus, ccColor4B disabled, CCObject* target, SEL_MenuHandler selector) { m_normalColor = normal; m_selectedColor = selected; m_focusColor = focus; m_disabledColor = disabled; setTarget(target, selector); updateColor(); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor)); }
bool HelloWorldScene::init() { if (!ImGuiLayer::init()) return false; addImGui([this] { auto director = Director::getInstance(); auto runningScene = director->getRunningScene(); static bool alwaysShow = true; ImGui::SetNextWindowPos(ImVec2(200, 50), ImGuiSetCond_Once); ImGui::Begin(" Scene", &alwaysShow, ImVec2(director->getWindowSize().width - 400, director->getWindowSize().height - 172), 0.0f, ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); ImGui::Text("%.1f FPS", ImGui::GetIO().Framerate); auto x = ImGui::GetWindowPos().x; auto y = ImGui::GetWindowPos().y; runningScene->setPosition(x, -y, 0.0); runningScene->setClipSize(Size(ImGui::GetWindowSize().x, ImGui::GetWindowSize().y)); ImGui::End(); ImGui::SetNextWindowPos(ImVec2(0, 100), ImGuiSetCond_Once); ImGui::Begin(" Hierarchy", &alwaysShow, ImVec2(200, director->getWindowSize().height - 172), 0.3f, ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); for (auto & child : _children) ImGui::Selectable(child->getName().c_str()); ImGui::End(); }); auto defaultShader = DefaultShader::createWithFileName("shaders/shader.shader"); for (int i = 0; i < 3000; ++i) { auto cube = Model3D::createWithFile("res/default_cube.xml"); cube->setName("Cube" + std::to_string(i)); cube->setShaderProgram(defaultShader); cube->setPosition(RandomHelper::random_int(-800, 300), RandomHelper::random_int(-300, 300), RandomHelper::random_int(-300, 300)); cube->setRotation(RandomHelper::random_int(-300, 300), RandomHelper::random_int(-300, 300), RandomHelper::random_int(-300, 300)); cube->setScale(5, 5, 5); addChild(cube); } auto texture = TextureCache::getInstance().addImage("res/wood.png"); return true; }