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