先上核心代码,基本的思路就是用黑色的同样轮廓的字体,向四周偏移一点,最后在把需要的字体叠加在画出来的轮廓上面。
cclabelTTF* pLabel = cclabelTTF::create("ABCDEFG","Arial",50);
pLabel->setposition(ccp(visibleSize.wIDth * 0.5,visibleSize.height * 0.5));this->addChild(pLabel,100);
CCRenderTexture* rt = CCRenderTexture::create(pLabel->getContentSize().wIDth,pLabel->getContentSize().height);
CCPoint originalPos = pLabel->getposition();
cccolor3B originalcolor = pLabel->getcolor();
bool originalVisibility = pLabel->isVisible();
pLabel->setcolor(ccc3(0,0));
pLabel->setVisible(true);
ccBlendFunc originalBlend = pLabel->getBlendFunc();
ccBlendFunc func = { GL_SRC_Alpha,GL_ONE};
pLabel->setBlendFunc(func);
pLabel->setAnchorPoint(ccp(0.5,0.5));
rt->begin();
for(int i = 0; i < 360; i += 15)
{
float r = CC_degrees_TO_radians(i);
pLabel->setposition(ccp(pLabel->getContentSize().wIDth * 0.5f + sin(r) * 2,
pLabel->getContentSize().height * 0.5f + cos(r) * 2));
pLabel->visit();
}
pLabel->setcolor(ccc3(0,255,0));
pLabel->setBlendFunc(originalBlend);
pLabel->setposition(ccp(pLabel->getContentSize().wIDth * 0.5f,pLabel->getContentSize().height * 0.5f));
pLabel->visit();
rt->end();
CCTexture2D* texture = rt->getSprite()->getTexture();
texture->setAliasTexParameters();
CCSprite* m_sprite = CCSprite::createWithTexture(rt->getSprite()->getTexture());
setContentSize(m_sprite->getContentSize());
m_sprite->setAnchorPoint(ccp(0,0));
m_sprite->setposition(ccp(0,0));
((CCSprite *)m_sprite)->setFlipY(true);
addChild(m_sprite);
这段代码主要是需要理解两个东西 1
OpenGL 会把源颜色和目标颜色各自取出,并乘以一个系数(源颜色乘以的系数称为“源因子”,目标颜色乘以的系数称为“目标因子”),然后相加,这样就得到了新的颜色。(也可以不是相加,新版本的OpenGL可以设置运算方式,包括加、减、取两者中较大的、取两者中较小的、逻辑运算等,但我们这里为了简单起见,不讨论这个了) 下面用数学公式来表达一下这个运算方式。假设源颜色的四个分量(指红色,绿色,蓝色,Alpha值)是(Rs,Gs,Bs,As),目标颜色的四个分量是(Rd,Gd,Bd,Ad),又设源因子为(Sr,Sg,Sb,Sa),目标因子为(Dr,Dg,Db,Da)。则混合产生的新颜色可以表示为: (Rs*Sr+Rd*Dr,Gs*Sg+Gd*Dg,Bs*Sb+Bd*Db,As*Sa+Ad*Da) 当然了,如果颜色的某一分量超过了1.0,则它会被自动截取为1.0,不需要考虑越界的问题。
2
以上是内存溢出为你收集整理的cocos2d-x 字体描边CCRenderTexture glBlendFunc全部内容,希望文章能够帮你解决cocos2d-x 字体描边CCRenderTexture glBlendFunc所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)