Javascript and WebGL, external scripts

前端 未结 4 1042
一个人的身影
一个人的身影 2020-12-13 14:26

Just curious; How do I place my webgl shaders, in an external file?

Currently I\'m having;

    

        
4条回答
  •  死守一世寂寞
    2020-12-13 15:10

    I had the same issue and found that this has worked for me with jQuery:

    var fragmentShaderSRC = null,
    var vertexShaderSRC = null;
    ...
    function executeProgram(){ //main program }
    ...
    $.get("shader.fs", function(data){ 
           fragmentShaderSRC = data.firstChild.textContent;
           $.get("shader.vs", function(data){
                 vertexShaderSRC = data.firstChild.textContent;
                 executeProgram();
           });
    });   
    

    Where shader.fs and shader.vs are my shaders (and include the

提交回复
热议问题