any Text node examples?

36 views
Skip to first unread message

Siddharth Vaghela

unread,
Jun 18, 2012, 3:55:25 AM6/18/12
to sce...@googlegroups.com
I saw that SceneJS does have text related code in the file but the usage is a bit hazy. Is there a text example that can clarify the usage of the text node?

Specfically, i am wondering how I can change the fonts on runtime, in order to handle two different languages.

regards,
Siddharth

Siddharth Vaghela

unread,
Jul 19, 2012, 6:54:09 AM7/19/12
to sce...@googlegroups.com
Managed to get the bitmap text working but faced a lot of problems with the blending of the text with the scene.

Finally, I had to resort to modifying the customer shader that scenejs compiles for the case where texture is applied to alpha in multiply blendmode.

In this conditional, i changed the code as follows:

/* Alpha from Texture
                 * */
                if (layer.applyTo == "alpha") {
                    if (layer.blendMode == "multiply") {
                        //src.push("alpha = alpha * texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).b;");
src.push("alpha = texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).a;");
src.push("color.rgb = color.rgb * texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb;");
                    } else if (layer.blendMode == "add") {
                        src.push("alpha = ((1.0 - SCENEJS_uLayer" + i + "BlendFactor) * alpha) + (SCENEJS_uLayer" + i + "BlendFactor * texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)).a);");
                    }
                }

And at the end, changed the way gl_fragcolor is updated:

Line: 9747
 if (debugCfg.whitewash == true) {
            src.push("    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);");
        } else {
src.push("if(alpha <= 0.0) { discard; } else {");
            src.push("    gl_FragColor = vec4(color.rgb, 1.0); }");
        }

I am basically discarding the fragment if the text background is being drawn.

Would love to have a cleaner way of dealing with this problem. Any thoughts? I wonder why blending does not work at all!!!!

regards,
Siddharth
Reply all
Reply to author
Forward
0 new messages