cocos2dxcocos 字体描边边与PScocos 字体描边边有什么区别

&>&&>&&>&&>&Cocos2d-x 2.x字体描边效果(Shader实现)
Cocos2d-x 2.x字体描边效果(Shader实现)
上传大小:3.27MB
Cocos2d-x 2.X实现的一基于CCLabelTTF + Shader的字体描边效果,具体可以参考这篇博客,http://blog.csdn.net/oktears/article/details/
综合评分:4.8(5位用户评分)
所需积分:0
下载次数:100
审核通过送C币
创建者:ch
创建者:doomlord
创建者:amixuse
课程推荐相关知识库
上传者其他资源上传者专辑
移动开发热门标签
VIP会员动态
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
Cocos2d-x 2.x字体描边效果(Shader实现)
会员到期时间:
剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:[原]cocos2d-x之字体描边效果shader实现 - 推酷
[原]cocos2d-x之字体描边效果shader实现
#ifdef GL_ES
uniform sampler2D u_
varying vec2 v_texC
varying vec4 v_fragmentC
//模糊blur的步长,这里只是demo,正式使用由外部传入(uniform类型)
const vec2 step = vec2(0.003, 0.002);
void main(void)
//获得当前点的颜色
vec3 color = texture2D(u_texture, v_texCoord).
//该权值用于自身对结果的影响
float weight = 30.0;
//加入alpha权重,alpha越大,权值assess越小
float assess = pow(texture2D(u_texture, v_texCoord).a, 3)*
//开始计算平均alpha值
float alpha =
//以下为高斯模糊(仅对alpha)
alpha += texture2D( u_texture, v_texCoord.st + vec2( -3.0*step.x, -3.0*step.y ) ).a;
alpha += texture2D( u_texture, v_texCoord.st + vec2( -2.0*step.x, -2.0*step.y ) ).a;
alpha += texture2D( u_texture, v_texCoord.st + vec2( -1.0*step.x, -1.0*step.y ) ).a;
alpha += texture2D( u_texture, v_texCoord.st + vec2( 0.0 , 0.0) ).a;
alpha += texture2D( u_texture, v_texCoord.st + vec2( 1.0*step.x,
1.0*step.y ) ).a;
alpha += texture2D( u_texture, v_texCoord.st + vec2( 2.0*step.x,
2.0*step.y ) ).a;
alpha += texture2D( u_texture, v_texCoord.st + vec2( 3.0*step.x, -3.0*step.y ) ).a;
alpha /= 7.0+
//alpha越大,对颜色影响越小
color = clamp(color + (alpha - 1.0), 0, 1.0);
//进一步加强颜色的区分
color = pow(color, vec3(3.0, 3.0, 3.0));
gl_FragColor = vec4(color.r, color.g, color.b, alpha);
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致bailu_1901 的BLOG
用户名:bailu_1901
访问量:1279
注册日期:
阅读量:5863
阅读量:12276
阅读量:418442
阅读量:1106465
51CTO推荐博文
参考 头文件#include "cocos2d.h"
class CCLabelTTFStroke : public cocos2d::CCNode
CCLabelTTFStroke();
~CCLabelTTFStroke();
static CCLabelTTFStroke* create(const char *string, const char *fontName, float fontSize, float strokeSize,const cocos2d::ccColor3B&
colStroke = cocos2d::ccc3(0, 0, 0), cocos2d::CCTextAlignment hAlignment=cocos2d::kCCTextAlignmentCenter, cocos2d::CCVerticalTextAlignment vAlignment=cocos2d::kCCVerticalTextAlignmentTop);
bool initWithString(const char *label, const char *fontName, float fontSize, float fStrokeSize, const cocos2d::ccColor3B&
colStroke, cocos2d::CCTextAlignment hAlignment, cocos2d::CCVerticalTextAlignment vAlignment);
void setColor(const cocos2d::ccColor3B& color3);
void setString(const char *label);
void setStrokeColor(cocos2d::ccColor3B col){ m_colStroke = updateStroke(); }
void setStrokeSize(float StrokeSize){ m_fStrokeSize = StrokeS updateStroke();}
protected:
void updateStroke();
m_fStrokeS
cocos2d::ccColor3B
cocos2d::CCSprite*
cocos2d::CCLabelTTF*
};源文件#include "CCStrokeLabel.h"
USING_NS_CC;
CCLabelTTFStroke::CCLabelTTFStroke()
:m_colStroke(ccc3(0,0,0))
,m_fStrokeSize(1.0f)
,m_sprite(NULL)
,m_label(NULL)
CCLabelTTFStroke::~CCLabelTTFStroke()
CC_SAFE_RELEASE_NULL(m_label);
bool CCLabelTTFStroke::initWithString(const char *string, const char *fontName, float fontSize, float strokeSize,const cocos2d::ccColor3B& colStroke, CCTextAlignment hAlignment,CCVerticalTextAlignment vAlignment)
m_fStrokeSize = strokeS
m_colStroke = colS
m_label = CCLabelTTF::create(string, fontName, fontSize, CCSizeZero,hAlignment,vAlignment);
m_label-&retain();
updateStroke();
CCLabelTTFStroke* CCLabelTTFStroke::create(const char *string, const char *fontName, float fontSize, float fStrokeSize,const cocos2d::ccColor3B& colStroke ,CCTextAlignment hAlignment,CCVerticalTextAlignment vAlignment)
CCLabelTTFStroke *pRet = new CCLabelTTFStroke();
if(pRet && pRet-&initWithString(string, fontName, fontSize, fStrokeSize, colStroke, hAlignment, vAlignment))
pRet-&autorelease();
CC_SAFE_DELETE(pRet);
return NULL;
void CCLabelTTFStroke::updateStroke()
if (m_sprite)
removeChild(m_sprite, true);
CCSize textureSize = m_label-&getContentSize();
textureSize.width += 2 * m_fStrokeS
textureSize.height += 2 * m_fStrokeS
//call to clear error
glGetError();
CCRenderTexture *rt = CCRenderTexture::create(textureSize.width, textureSize.height);
CCLOG("create render texture failed !!!!");
addChild(m_label);
ccColor3B col = m_label-&getColor();
m_label-&setColor(m_colStroke);
ccBlendFunc originalBlend = m_label-&getBlendFunc();
ccBlendFunc func = { GL_SRC_ALPHA, GL_ONE};
m_label-&setBlendFunc(func);
m_label-&setAnchorPoint(ccp(0.5, 0.5));
rt-&begin();
for(int i = 0; i & 360; i += 15)
float r = CC_DEGREES_TO_RADIANS(i);
m_label-&setPosition(ccp(
textureSize.width * 0.5f + sin(r) * m_fStrokeSize,
textureSize.height * 0.5f + cos(r) * m_fStrokeSize));
m_label-&visit();
m_label-&setColor(col);
m_label-&setBlendFunc(originalBlend);
m_label-&setPosition(ccp(textureSize.width * 0.5f, textureSize.height * 0.5f));
m_label-&visit();
rt-&end();
CCTexture2D *texture = rt-&getSprite()-&getTexture();
texture-&setAliasTexParameters();
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);
void CCLabelTTFStroke::setString(const char *label)
if (m_label)
if(0!=strcmp(label, m_label-&getString()))
m_label-&setString(label);
updateStroke();
CCLOG("ERROR:CCLabelTTFStroke::setString m_label=NULL");
void CCLabelTTFStroke::setColor(const ccColor3B& color3)
if (m_label)
ccColor3B col = m_label-&getColor();
if(color3.r!=col.r && color3.g!=col.g && color3.b!=col.b)
m_label-&setColor(color3);
updateStroke();
CCLOG("ERROR:CCLabelTTFStroke::setColor m_label=NULL");
了这篇文章
类别:┆阅读(0)┆评论(0)cocos2dx中CCLabelTTF的描边和阴影
游戏中经常会用到文字描边和阴影,当cocos2dx中并没有给我们提供,下面是我参考:点击打开链接(http://blog.csdn.net/song_hui_xiang/article/details/)自己弄了一个,基本上是一模一样,不喜勿喷!代码如下:
思路:多个CCLabelTTF重叠在一起。
Created by user on 14-3-4.
#ifndef __XXX__CLabel__
#define __XXX__CLabel__
#include "cocos2d.h"
USING_NS_CC;
namespace CLabel{
/*使用示例
CCSize size = CCDirector::sharedDirector()->getWinSize();
//创建个背景
CCLayerColor* whiteLayer = CCLayerColor::create(ccc4(0, 205, 205, 255), size.width, size.height);
this->addChild(whiteLayer);
//创建描边
CCLabelTTF* outline = CLabel::textAddOutline("描边 Outline", "Arial", 40, ccWHITE, 1);
outline->setPosition(ccp(size.width*0.5, size.height*0.7));
this->addChild(outline);
//创建阴影
CCLabelTTF* shadow = CLabel::textAddShadow("阴影 Shadow", "Arial", 40, ccWHITE, 2, 200);
shadow->setPosition(ccp(size.width*0.5, size.height*0.5));
this->addChild(shadow);
//创建描边加阴影
CCLabelTTF* outlineShadow = CLabel::textAddOutlineAndShadow("描边加阴影 OutlineShadow", "Arial", 40, ccWHITE, 1, 4, 200);
outlineShadow->setPosition(ccp(size.width*0.5, size.height*0.3));
this->addChild(outlineShadow);
//**************************************************************************
// 给文字添加描边
//**************************************************************************
CCLabelTTF* textAddOutline(const char* string,
// 显示的文字
const char* fontName,
// 字体名称
float fontSize,
// 字体大小
const ccColor3B &color3,
// 字体颜色
float lineWidth);
// 描边宽度
//**************************************************************************
// 添加阴影
CCLabelTTF* textAddShadow(const char* string,
// 显示的文字
const char* fontName,
// 字体名称
float fontSize,
// 字体大小
const ccColor3B &color3,
// 字体颜色
float shadowSize,
// 阴影宽度
float shadowOpacity);
// 阴影透明度
//**************************************************************************
//**************************************************************************
// 既添加描边又添加阴影
//**************************************************************************
CCLabelTTF* textAddOutlineAndShadow(const char* string,
// 显示的文字
const char* fontName,
// 字体名称
float fontSize,
// 字体大小
const ccColor3B &color3,// 阴影颜色
float lineWidth,
// 字体宽度
float shadowSize,
// 阴影宽度
float shadowOpacity);
// 阴影透明度
#endif /* defined(__XXX__CLabel__) */
CLabel.cpp
Created by user on 14-3-4.
#include "CLabel.h"
namespace CLabel{
制作文字描边效果是很简单的,我们写好一段文字之后,也就是创建出一个CCLabelTTF,称之为正文CCLabelTTF。然后再创建出4个CCLabelTTF,颜色为黑色,大小同正文CCLabelTTF相同,
称之为描边CCLabelTTF。说到这大家可能已经明白了,没错,就是把4个描边CCLabelTTF放于正文CCLabelTTF的下面,分别于左右上下与正文CCLabelTTF错开,这样描边效果就实现啦。。
文本字体类型
*lineWidth
所描边的宽度
CCLabelTTF* textAddOutline(const char* string, const char* fontName, float fontSize,const ccColor3B &color3,float lineWidth)
//描边CCLabelTTF 左
CCLabelTTF* left = CCLabelTTF::create(string, fontName, fontSize);
left->setColor(ccBLACK);
//描边CCLabelTTF 右
CCLabelTTF* right = CCLabelTTF::create(string, fontName, fontSize);
right->setColor(ccBLACK);
right->setPosition(ccp(left->getContentSize().width*0.5+lineWidth*2,left->getContentSize().height*0.5));
left->addChild(right);
//描边CCLabelTTF 上
CCLabelTTF* up = CCLabelTTF::create(string, fontName, fontSize);
up->setColor(ccBLACK);
up->setPosition(ccp(left->getContentSize().width*0.5+lineWidth, left->getContentSize().height*0.5+lineWidth));
left->addChild(up);
//描边CCLabelTTF 下
CCLabelTTF* down = CCLabelTTF::create(string, fontName, fontSize);
down->setColor(ccBLACK);
down->setPosition(ccp(left->getContentSize().width*0.5+lineWidth, left->getContentSize().height*0.5-lineWidth));
left->addChild(down);
//正文CCLabelTTF
CCLabelTTF* center = CCLabelTTF::create(string, fontName, fontSize);
center->setColor(color3);
center->setPosition(ccp(left->getContentSize().width*0.5+lineWidth, left->getContentSize().height*0.5));
left->addChild(center);
给文字添加阴影,一看就懂的。。。
文本字体类型
*shadowSize
*shadowOpacity
阴影透明度
CCLabelTTF* textAddShadow(const char* string, const char* fontName, float fontSize,const ccColor3B &color3,float shadowSize,float shadowOpacity)
CCLabelTTF* shadow = CCLabelTTF::create(string, fontName, fontSize);
shadow->setColor(ccBLACK);
shadow->setOpacity(shadowOpacity);
CCLabelTTF* center = CCLabelTTF::create(string, fontName, fontSize);
center->setColor(color3);
center->setPosition(ccp(shadow->getContentSize().width*0.5-shadowSize, shadow->getContentSize().height*0.5+shadowSize));
shadow->addChild(center);
//既添加描边又添加阴影
CCLabelTTF* textAddOutlineAndShadow(const char* string, const char* fontName, float fontSize,const ccColor3B &color3,float lineWidth,float shadowSize,float shadowOpacity)
CCLabelTTF* shadow = CCLabelTTF::create(string, fontName, fontSize);
shadow->setColor(ccBLACK);
shadow->setOpacity(shadowOpacity);
CCLabelTTF* left = CCLabelTTF::create(string, fontName, fontSize);
left->setColor(ccBLACK);
left->setPosition(ccp(shadow->getContentSize().width*0.5-shadowSize, shadow->getContentSize().height*0.5+shadowSize));
shadow->addChild(left);
CCLabelTTF* right = CCLabelTTF::create(string, fontName, fontSize);
right->setColor(ccBLACK);
right->setPosition(ccp(left->getContentSize().width*0.5+lineWidth*2,left->getContentSize().height*0.5));
left->addChild(right);
CCLabelTTF* up = CCLabelTTF::create(string, fontName, fontSize);
up->setColor(ccBLACK);
up->setPosition(ccp(left->getContentSize().width*0.5+lineWidth, left->getContentSize().height*0.5+lineWidth));
left->addChild(up);
CCLabelTTF* down = CCLabelTTF::create(string, fontName, fontSize);
down->setColor(ccBLACK);
down->setPosition(ccp(left->getContentSize().width*0.5+lineWidth, left->getContentSize().height*0.5-lineWidth));
left->addChild(down);
CCLabelTTF* center = CCLabelTTF::create(string, fontName, fontSize);
center->setColor(color3);
center->setPosition(ccp(left->getContentSize().width*0.5+lineWidth, left->getContentSize().height*0.5));
left->addChild(center);
使用时,加上命名空间就可以拉,下面是使用示例:
CCSize size = CCDirector::sharedDirector()->getWinSize();
//创建描边
CCLabelTTF* outline = CLabel::textAddOutline("描边 Outline", "Arial", 40, ccWHITE, 1);
outline->setPosition(ccp(size.width*0.5, size.height*0.7));
this->addChild(outline);
//创建阴影
CCLabelTTF* shadow = CLabel::textAddShadow("阴影 Shadow", "Arial", 40, ccWHITE, 2, 200);
shadow->setPosition(ccp(size.width*0.5, size.height*0.5));
this->addChild(shadow);
//创建描边加阴影
CCLabelTTF* outlineShadow = CLabel::textAddOutlineAndShadow("描边加阴影 OutlineShadow", "Arial", 40, ccWHITE, 1, 4, 200);
outlineShadow->setPosition(ccp(size.width*0.5, size.height*0.3));
this->addChild(outlineShadow);&>&&>&&>&&>&cocos2dx字体描边
cocos2dx字体描边
上传大小:1KB
cocos2dx字体描边 接口简单 调用方便
综合评分:3(2位用户评分)
所需积分:2
下载次数:27
审核通过送C币
创建者:xamhaha
创建者:qq
创建者:wty1009
课程推荐相关知识库
上传者其他资源上传者专辑
开发技术热门标签
VIP会员动态
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
cocos2dx字体描边
会员到期时间:
剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
xuanforxin
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:

我要回帖

更多关于 cocos2dx shader 描边 的文章

 

随机推荐