开发者

Javascript text input editing: How to turn multiple string text shader in one text input into another representation?

So I want to have 2 input feilds, one editable. I need some script that would turn such shader text input:

    #ifdef GL_ES
    precision highp float;
    #endif

    varying vec4 v_color;

    void main (void)
    {
      gl_FragColor = v_color; 
    }

into such ou开发者_如何学Pythontput:

    "#ifdef GL_ES\n"
    "precision highp float;\n"
    "#endif\n"
    "\n"
    "varying vec4 v_color;\n"
    "\n"
    "void main (void)\n"
    "{\n"
    "    gl_FragColor = v_color;    \n"
    "}"

(such output can be turned into openGL shader static char* )

So how to create such simple tool with Javascript?


try regular expressions.

html:

<textarea id="text1">#ifdef GL_ES
precision highp float;
#endif

varying vec4 v_color;

void main (void)
{
gl_FragColor = v_color;
}
</textarea>
<textarea id="text2"></textarea>

javascript:

var text = document.getElementById("text1").value;
text = text.replace(/\n/g, "\\n\"\n\"");
document.getElementById("text2").value = "\""+text+"\\n\"";

http://jsfiddle.net/t9sgA/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜