mirror of https://github.com/axmolengine/axmol.git
Does not crash on Mac if the .ttf file is not found
This commit is contained in:
parent
0cfc7827de
commit
7e4597508c
|
@ -349,20 +349,20 @@ void Label::updateShaderProgram()
|
|||
break;
|
||||
case cocos2d::LabelEffect::OUTLINE:
|
||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_OUTLINE));
|
||||
_uniformEffectColor = glGetUniformLocation(getGLProgram()->getProgram(), "v_effectColor");
|
||||
_uniformEffectColor = glGetUniformLocation(getGLProgram()->getProgram(), "u_effectColor");
|
||||
break;
|
||||
case cocos2d::LabelEffect::GLOW:
|
||||
if (_useDistanceField)
|
||||
{
|
||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW));
|
||||
_uniformEffectColor = glGetUniformLocation(getGLProgram()->getProgram(), "v_effectColor");
|
||||
_uniformEffectColor = glGetUniformLocation(getGLProgram()->getProgram(), "u_effectColor");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_uniformTextColor = glGetUniformLocation(getGLProgram()->getProgram(), "v_textColor");
|
||||
_uniformTextColor = glGetUniformLocation(getGLProgram()->getProgram(), "u_textColor");
|
||||
}
|
||||
|
||||
void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false */, bool useA8Shader /* = false */)
|
||||
|
|
|
@ -5,8 +5,9 @@ precision lowp float;
|
|||
\n#endif\n
|
||||
|
||||
varying vec4 v_fragmentColor;
|
||||
varying vec2 v_texCoord;
|
||||
uniform vec4 v_textColor;
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
uniform vec4 u_textColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ void main()
|
|||
//float width = fwidth(dist); \n
|
||||
//assign width for constant will lead to a little bit fuzzy,it's temporary measure.\n
|
||||
float width = 0.04;
|
||||
float alpha = smoothstep(0.5-width, 0.5+width, dist) * v_textColor.a;
|
||||
gl_FragColor = v_fragmentColor * vec4(v_textColor.rgb,alpha);
|
||||
float alpha = smoothstep(0.5-width, 0.5+width, dist) * u_textColor.a;
|
||||
gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb,alpha);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -5,9 +5,10 @@ precision lowp float;
|
|||
\n#endif\n
|
||||
|
||||
varying vec4 v_fragmentColor;
|
||||
varying vec2 v_texCoord;
|
||||
uniform vec4 v_effectColor;
|
||||
uniform vec4 v_textColor;
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
uniform vec4 u_effectColor;
|
||||
uniform vec4 u_textColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ void main()
|
|||
float alpha = smoothstep(0.5-width, 0.5+width, dist);
|
||||
//glow \n
|
||||
float mu = smoothstep(0.5, 1.0, sqrt(dist));
|
||||
vec4 color = v_effectColor*(1.0-alpha) + v_textColor*alpha;
|
||||
vec4 color = u_effectColor*(1.0-alpha) + u_textColor*alpha;
|
||||
gl_FragColor = v_fragmentColor * vec4(color.rgb, max(alpha,mu)*color.a);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -30,12 +30,13 @@ precision lowp float;
|
|||
|
||||
varying vec4 v_fragmentColor;
|
||||
varying vec2 v_texCoord;
|
||||
uniform vec4 v_textColor;
|
||||
|
||||
uniform vec4 u_textColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = v_fragmentColor * vec4( v_textColor.rgb,// RGB from uniform\n
|
||||
v_textColor.a * texture2D(CC_Texture0, v_texCoord).a// A from texture & uniform\n
|
||||
gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb,// RGB from uniform\n
|
||||
u_textColor.a * texture2D(CC_Texture0, v_texCoord).a// A from texture & uniform\n
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -7,9 +7,10 @@ precision lowp float;
|
|||
\n#endif\n
|
||||
|
||||
varying vec4 v_fragmentColor;
|
||||
varying vec2 v_texCoord;
|
||||
uniform vec4 v_effectColor;
|
||||
uniform vec4 v_textColor;
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
uniform vec4 u_effectColor;
|
||||
uniform vec4 u_textColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -17,7 +18,7 @@ void main()
|
|||
float fontAlpha = sample.a;
|
||||
float outlineAlpha = sample.r;
|
||||
if (outlineAlpha > 0.0){
|
||||
vec4 color = v_textColor * fontAlpha + v_effectColor * (1.0 - fontAlpha);
|
||||
vec4 color = u_textColor * fontAlpha + u_effectColor * (1.0 - fontAlpha);
|
||||
gl_FragColor = v_fragmentColor * vec4( color.rgb,max(fontAlpha,outlineAlpha)*color.a);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -607,8 +607,11 @@ LabelTTFUnicodeChinese::LabelTTFUnicodeChinese()
|
|||
// like "Error 3 error C2146: syntax error : missing ')' before identifier 'label'";
|
||||
TTFConfig ttfConfig("fonts/wt021.ttf",28,GlyphCollection::CUSTOM, "美好的一天啊");
|
||||
auto label = Label::createWithTTF(ttfConfig,"美好的一天啊", TextHAlignment::CENTER, size.width);
|
||||
label->setPosition(Vec2(size.width / 2, size.height /2));
|
||||
this->addChild(label);
|
||||
|
||||
if(label) {
|
||||
label->setPosition(Vec2(size.width / 2, size.height /2));
|
||||
this->addChild(label);
|
||||
}
|
||||
}
|
||||
|
||||
std::string LabelTTFUnicodeChinese::title() const
|
||||
|
@ -966,8 +969,10 @@ LabelTTFLargeText::LabelTTFLargeText()
|
|||
TTFConfig ttfConfig("fonts/wt021.ttf",18,GlyphCollection::DYNAMIC);
|
||||
std::string text = FileUtils::getInstance()->getStringFromFile("commonly_used_words.txt");
|
||||
auto label = Label::createWithTTF(ttfConfig,text, TextHAlignment::CENTER, size.width);
|
||||
label->setPosition( Vec2(size.width/2, size.height/2) );
|
||||
addChild(label);
|
||||
if(label) {
|
||||
label->setPosition( Vec2(size.width/2, size.height/2) );
|
||||
addChild(label);
|
||||
}
|
||||
}
|
||||
|
||||
std::string LabelTTFLargeText::title() const
|
||||
|
@ -1090,23 +1095,30 @@ LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
|
|||
TTFConfig ttfConfig("fonts/wt021.ttf", 25, GlyphCollection::DYNAMIC);
|
||||
auto label1 = Label::createWithTTF(ttfConfig,
|
||||
"你好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75);
|
||||
label1->setTextColor(Color4B(128, 255, 255, 255));
|
||||
label1->setPosition(Vec2(size.width * 0.1, size.height * 0.6));
|
||||
label1->setAnchorPoint(Vec2(0, 0.5));
|
||||
this->addChild(label1);
|
||||
|
||||
if(label1) {
|
||||
label1->setTextColor(Color4B(128, 255, 255, 255));
|
||||
label1->setPosition(Vec2(size.width * 0.1, size.height * 0.6));
|
||||
label1->setAnchorPoint(Vec2(0, 0.5));
|
||||
this->addChild(label1);
|
||||
}
|
||||
|
||||
auto label2 = Label::createWithTTF(ttfConfig,
|
||||
"早上好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75);
|
||||
label2->setTextColor(Color4B(255, 128, 255, 255));
|
||||
label2->setPosition(Vec2(size.width * 0.1, size.height * 0.4));
|
||||
label2->setAnchorPoint(Vec2(0, 0.5));
|
||||
this->addChild(label2);
|
||||
if(label2) {
|
||||
label2->setTextColor(Color4B(255, 128, 255, 255));
|
||||
label2->setPosition(Vec2(size.width * 0.1, size.height * 0.4));
|
||||
label2->setAnchorPoint(Vec2(0, 0.5));
|
||||
this->addChild(label2);
|
||||
}
|
||||
|
||||
auto label3 = Label::createWithTTF(ttfConfig,
|
||||
"美好的一天啊美好的一天啊美好的一天啊", TextHAlignment::LEFT, size.width * 0.75);
|
||||
label3->setTextColor(Color4B(255, 255, 128, 255));
|
||||
label3->setPosition(Vec2(size.width * 0.1, size.height * 0.2));
|
||||
label3->setAnchorPoint(Vec2(0, 0.5));
|
||||
this->addChild(label3);
|
||||
if(label3) {
|
||||
label3->setTextColor(Color4B(255, 255, 128, 255));
|
||||
label3->setPosition(Vec2(size.width * 0.1, size.height * 0.2));
|
||||
label3->setAnchorPoint(Vec2(0, 0.5));
|
||||
this->addChild(label3);
|
||||
}
|
||||
}
|
||||
|
||||
std::string LabelTTFCJKWrappingTest::title() const
|
||||
|
@ -1153,8 +1165,10 @@ LabelTTFUnicodeNew::LabelTTFUnicodeNew()
|
|||
ttfConfig.glyphs = GlyphCollection::CUSTOM;
|
||||
ttfConfig.customGlyphs = chinese.c_str();
|
||||
auto label3 = Label::createWithTTF(ttfConfig,chinese, TextHAlignment::CENTER,size.width);
|
||||
label3->setPosition( Vec2(size.width/2, vSize - (vStep * 6.5)) );
|
||||
addChild(label3);
|
||||
if(label3) {
|
||||
label3->setPosition( Vec2(size.width/2, vSize - (vStep * 6.5)) );
|
||||
addChild(label3);
|
||||
}
|
||||
}
|
||||
|
||||
std::string LabelTTFUnicodeNew::title() const
|
||||
|
|
Loading…
Reference in New Issue