cocos2dx中怎么使BMFont字体变灰

 我来答
缘Lai如茨
2016-05-25 · TA获得超过8630个赞
知道大有可为答主
回答量:7534
采纳率:92%
帮助的人:629万
展开全部
随便整个BMFont字体变灰,然后设置位置,你就会发现了。我的变灰代码是这样写的:

static void turnGray(Node* s)
{
GLProgram* program = GLProgramCache::getInstance()->getGLProgram("gard_key");
if (program == NULL) {
const GLchar* vsh = "attribute vec4 a_position;\
attribute vec2 a_texCoord;\
attribute vec4 a_color;\
\
varying vec4 v_fragmentColor;\
varying vec2 v_texCoord;\
\
void main()\
{\
gl_Position = CC_PMatrix * a_position;\
v_fragmentColor = a_color;\
v_texCoord = a_texCoord;\
}";

const GLchar* fsh = "varying vec4 v_fragmentColor;\
varying vec2 v_texCoord;\
\
void main()\
{\
vec4 v_orColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);\
float gray = dot(v_orColor.rgb, vec3(0.299, 0.587, 0.114));\
gl_FragColor = vec4(gray, gray, gray, v_orColor.a);\
}";

program = new GLProgram();
program->autorelease();
program->initWithByteArrays(vsh, fsh);
CHECK_GL_ERROR_DEBUG();

program->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
program->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_TEX_COORD);
program->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD);
CHECK_GL_ERROR_DEBUG();

program->link();
CHECK_GL_ERROR_DEBUG();

program->updateUniforms();
CHECK_GL_ERROR_DEBUG();

GLProgramCache::getInstance()->addGLProgram(program, "gray_key");
}
s->setGLProgram(program);
}
auto bm = Label::createWithBMFont("res/fonts/na.fnt", "abcd");
addChild(bm);
turnGray(bm);
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式