cocos2dx中怎么使BMFont字体变灰
1个回答
展开全部
随便整个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);
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);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询